Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Strings and variables

Hi!
Please help me with my problem.
For example I have the string "PWW-304-5689".
How can I make, that the variable "v1" will have the value PWW,
the "v2" 304 and "v3" 5689?
Please post your messages on my email. Thanks.

Triangel

Comments


  • You could use an array.

    [code]var
    v : array[0..3] of string;

    begin
    v[1] := 'PWW';
    v[2] := '304';
    v[3] := '5689';
    writeln(v[1],'-',v[2],'-',v[3]);
    end.[/code]

    -- spida.

    : Hi!
    : Please help me with my problem.
    : For example I have the string "PWW-304-5689".
    : How can I make, that the variable "v1" will have the value PWW,
    : the "v2" 304 and "v3" 5689?
    : Please post your messages on my email. Thanks.
    :
    : Triangel
    :


  • :
    : You could use an array.
    :
    : [code]var
    : v : array[0..3] of string;
    :
    : begin
    : v[1] := 'PWW';
    : v[2] := '304';
    : v[3] := '5689';
    : writeln(v[1],'-',v[2],'-',v[3]);
    : end.[/code]
    :
    : -- spida.
    :
    : : Hi!
    : : Please help me with my problem.
    : : For example I have the string "PWW-304-5689".
    : : How can I make, that the variable "v1" will have the value PWW,
    : : the "v2" 304 and "v3" 5689?
    : : Please post your messages on my email. Thanks.
    : :
    : : Triangel
    : :
    :
    :


    Spida, I think what he wants is to do is brake down the string into it's parts separated by minus sign. Triangel, check instructions such as POS and COPY in this case (and INSERT, DELETE if you want to have broad knoweledege of string manipulation).

    Iby

  • : Spida, I think what he wants is to do is brake down the string into it's parts separated by minus sign. Triangel, check instructions such as POS and COPY in this case (and INSERT, DELETE if you want to have broad knoweledege of string manipulation).
    :
    : Iby

    Ok, if that's the case, then he/she would have to just add a little extra code to the example:

    [code]var
    v : array[0..3] of string;
    vstring : string; {or could be array[0..255] of char}
    vcount1, vcount2 : byte;

    begin
    vstring := 'xxx-xxx-xxx';
    vcount1 := 1;
    vcount2 := 1;
    repeat
    while (vstring[vcount1] <> '-') and (vstring[vcount1] <> #0) do
    begin
    v[vcount2] := v[vcount2] + vstring[vcount1];
    vcount1 := vcount1 + 1;
    end;
    vcount1 := vcount1 + 1;
    vcount2 := vcount2 + 1;
    until vcount2 = 4;
    writeln(vstring); {verify the orignal string...}
    writeln(v[1],'-',v[2],'-',v[3]); {with the new string}
    readln;
    end.[/code]

    good luck.
    -- Spida.

  • i guess i shoulda posted, but i sent him working code like, before you guys started answering him..he emailed me that it works.. just wanted to let you know so this thread doesn't get too long, or so no1 gets surprised if he doesn't eventually answer or say thanx, etc..
    well i guess that's all..
    [blue]//Noam[/blue]


  • ...and not an automatic email service.
    If your going to reply, post it here!

    Jeeze :-o

    : i guess i shoulda posted, but i sent him working code like, before you guys started answering him..he emailed me that it works.. just wanted to let you know so this thread doesn't get too long, or so no1 gets surprised if he doesn't eventually answer or say thanx, etc..

  • : i guess i shoulda posted, but i sent him working code like, before you guys started answering him..he emailed me that it works.. just wanted to let you know so this thread doesn't get too long, or so no1 gets surprised if he doesn't eventually answer or say thanx, etc..
    : well i guess that's all..
    : [blue]//Noam[/blue]
    :

    hey, it even can be interesting, if a simple question develops
    into a longer thread. sometimes somebody even says something
    you never thought about (well, this might not be the case for
    this thread, but anyway)

    besides, i think too that answers should be posted on the board. i usually don't mail ppl answers, if they can post questions on this board, they should be able to read the replies too, right ?


  • :
    : You could use an array.
    :
    : [code]var
    : v : array[0..3] of string;
    :
    : begin
    : v[1] := 'PWW';
    : v[2] := '304';
    : v[3] := '5689';
    : writeln(v[1],'-',v[2],'-',v[3]);
    : end.[/code]
    :
    : -- spida.
    :
    are you wanting to extract from the string ?
    then using another string variable you can extract the first 3 characters from the left.

    ok! I am not at home with my books to give you the pascal code
    But I know you can

    I shall check when home on Friday

    : : Hi!
    : : Please help me with my problem.
    : : For example I have the string "PWW-304-5689".
    : : How can I make, that the variable "v1" will have the value PWW,
    : : the "v2" 304 and "v3" 5689?
    : : Please post your messages on my email. Thanks.
    : :
    : : Triangel
    : :
    :
    :


Sign In or Register to comment.