visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: Pascal :: Read a array with a string


By: collegeBoy U.S.A.  Date: 30/10/2002 00:00:00  English  Points: 50 Status: Answered
Quality : Excellent
am from chile sorry for my english

i have de follow porblem with college job

PROGRAM CONTROL3;

USES CRT;

VAR i,users,opcion:INTEGER;
VAR arreglo:ARRAY [1..users] of STRING[63];
VAR var1, opc, datos, nombre1, nombre2, materno, paterno, rut dv:STRING;
VAR i,users,opcion:INTEGER;


BEGIN
Clrscr;
users:=2
FOR i:=1 TO users DO
BEGIN
Clrscr;

WRITELN ('INGRESE NUMERO DE RUT '); READLN (var1);
INSERT (var1,arreglo,1);

WRITELN ('INGRESE DIGITO VERIFICADOR '); READLN (var1);
INSERT (var1,arreglo,9);

WRITELN ('INGRESE APELLIDO PATERNO '); READLN (var1);
INSERT (var1,arreglo,10);

WRITELN ('INGRESE APELLIDO MATERNO '); READLN (var1);
INSERT (var1,arreglo,25);

WRITELN ('INGRESE PRIMER NOMBRE '); READLN (var1);
INSERT (var1,arreglo,40);

WRITELN ('INGRESE SEGUNDO NOMBRE '); READLN (var1);
INSERT (var1,arreglo,52);
END;
________________________

this array have a string with information, i need search into de array looking the string,.
How can read array, and read a part string into array.
for example only compare a part of string with a variable.
hope your help

thanks


By: monange Date: 30/10/2002 08:47:00 English  Type : Comment
You are using the array to store all of the information for the different variables.

A better data structure would be an array of records rather than an array of strings.

Are you famaliar with records?


By: VGR Date: 01/11/2002 08:58:00 English  Type : Answer
okay.
So your problem is "How can read array, and read a part string into array."

And sorry but records will do you no good in here. I adore them, but it's not your problem 8-)

Given that you do things like INSERT (var1,arreglo,1); and INSERT (var1,arreglo,9);

It is trivial that you will find back your string data at positions 1 and 9 of the arreglo array, ie by using Copy() - extracts a substring - like this :
firstpart:=Copy(arreglo,1,8);
secondpart:=Copy(arreglo,9,2);
etc etc etc


If, as I suspect, you are only concerned with comparing values from the string (in the array) with equivalent of original variables, then I would suggest writing a procedure that extracts from arreglo the values of N variables (in a record to save space, of in an array of string)
Then you would be able to "compare" things with other variables in the way you would like.

I hope I did understand you correctly
By: FiatLink Date: 10/11/2002 18:00:00 English  Type : Comment
I see a problem here,
Strings have variable length so inserting at a specified position an other string does not assure the new length of the string (the actual length) to the specified size. Why don't you use a record of chars instead?
like

UserRec = Record
numero: array[1..8] of char;
ver : Char;
Name : Array[1..15] of char;
.......
end;

VAR arreglo:ARRAY [1..users] of UserRec;

By: TheFalklands Date: 27/11/2002 01:57:00 English  Type : Assist
I don't fully understand your question, but this may help you out:

To compare a "part" of a string with a variable, you should use the Copy function: (Remember thar VGR was the first to tell you this)

Copy(str : string; from, howlong : word) : string

For example:

Var
a, b : string;
Begin
a := 'Hello, World!';
b := Copy(a, 1, 5); {In this case, b := 'Hello'}
End.

Then, if you want to compare it with another string, it's simply:

If Copy(a, 1, 5) = another_string Then ...

Now, you said you want to find a string inside an array of string...I think. In order to find substrings inside strings there's the function Pos.

Pos(substr, str : string) : byte;
It searches -substr- in -str-. If it founds it, it yields its position, or else it yields 0.

For example:

Var
result : byte;
Begin
result := Pos('World', 'Hello World!!'); {Pos yields 7}
{Another example}
result := Pos('Goodbye', 'Hello World!!'); {Pos yields 0}
End.

Then the 'if' is as follows:

If Pos(substr, str) <> 0 Then ... {If the string is found, then...}

Finally, if you want to find a "part" of a string in an array of string you do like this:

For i := 1 To max_number_array Do
Begin
If Pos(string_to_find, array) <> 0 Then -StringFound!!!-
End;

Hope it helped...
TFL

Do register to be able to answer

EContact
browser fav
page generated in 298.903940 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page