Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Edit Report
Strings and variables Posted by Triangel on 27 Jan 2001 at 9:56 AM
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

Edit Report
Re: Strings and variables Posted by spida on 27 Jan 2001 at 9:23 PM

You could use an array.

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.


-- 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
:


Edit Report
Re: Strings and variables Posted by iby... on 28 Jan 2001 at 3:16 PM
:
: You could use an array.
:
:
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.

:
: -- 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

Edit Report
maybe. if that's the case... Posted by spida on 28 Jan 2001 at 9:33 PM
: 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:

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.


good luck.
-- Spida.

Edit Report
err..you can stop suggesting things.. Posted by Noam on 29 Jan 2001 at 11:30 AM
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..
//Noam

Edit Report
it's a messageboard... Posted by spida on 29 Jan 2001 at 6:42 PM

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

Jeeze

: 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..

Edit Report
Re: err..you can stop suggesting things.. Posted by ann... on 30 Jan 2001 at 3:22 AM
: 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..
: //Noam
:

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 ?


Edit Report
Re: Strings and variables Posted by MichaelBarkerAustral on 30 Jan 2001 at 8:27 PM
:
: You could use an array.
:
:
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.

:
: -- 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
: :
:
:





 

Recent Jobs