SRL Archive - OSR Help

String to Array? or Selecting a WORD in a string


halgboy_tbc

2013-03-29 18:01:21

I want to, with a string of words, pick out one of the words or multiple words (the goal to find a username which was be one or more words).

Here is an example of what I am trying to do:

For instance:
"Wizz Up has logged in."

S:='Wizz Up has logged in.' {String would be from gettextatexwrap}

How can I get the user name (Wizz Up) from the string?

So I have came up with making the string into a tstringarray and search high to low(text) for "has (The word not the chars h,a,s)" and then, in this case, backtrack from there and find the two words (in this case) that make up the username. But I do not know how to make the words into an array.


—
A seperate issue and another thing that I am trying to do is to find some skill levels of the player who was just found.
I would be using getpage and trying to find the Construction level from that string. I will maybe try doing this the same way as finding the username? But does anyone have tips?

Thanks

Runehack123

2013-03-29 18:18:46

you mean string to array of string?

halgboy_tbc

2013-03-29 19:13:07

From: Runehack123
you mean string to array of string?


I think what I explained describes the goal I'm trying to accomplish.

tealc

2013-03-29 19:28:31

This should work as long as their name doesn't contain 'has', search "pascal (script) string manipulation" to see more functions.
Post if need more help
program new;
Var
S,username : String;
I:integer;
Begin
S := 'Wizz Up has logged in.';
Writeln('The word "has" is found at char index ');
Writeln(Pos('has',S));
I:=Pos('has',S);
username := Copy(S, 0, i-2);
Writeln(username);

end.

Le Jingle

2013-03-29 19:40:49

one way to go about it:

{$include_once srl/srl.simba}
var
place1, place2: Integer;
s: string;
TSA: TStringArray;
begin
s := 'Wizz Up has logged in.';

// break up the string, s with the delimiter, ' '
ExplodeWrap(' ', s, TSA);
if (InStrArrEx('Wizz', TSA, place1) and InStrArrEx('Up', TSA, place2)) then
if (place2 - place1 = 1) then
Writeln('Found user');
end.

halgboy_tbc

2013-03-29 20:40:16

From: tealc
This should work as long as their name doesn't contain 'has', search "pascal (script) string manipulation" to see more functions.
Post if need more help
program new;
Var
S,username : String;
I:integer;
Begin
S := 'Wizz Up has logged in.';
Writeln('The word "has" is found at char index ');
Writeln(Pos('has',S));
I:=Pos('has',S);
username := Copy(S, 0, i-2);
Writeln(username);

end.


From: Le Jingle
one way to go about it:

{$include_once srl/srl.simba}
var
place1, place2: Integer;
s: string;
TSA: TStringArray;
begin
s := 'Wizz Up has logged in.';

// break up the string, s with the delimiter, ' '
ExplodeWrap(' ', s, TSA);
if (InStrArrEx('Wizz', TSA, place1) and InStrArrEx('Up', TSA, place2)) then
if (place2 - place1 = 1) then
Writeln('Found user');
end.



Thanks! Learned a lot from these examples.

Runehack123

2013-03-30 05:42:24

okay so you DID mean string to array of string

array on it's own makes no sense

Janilabo

2013-03-30 11:28:43

Easy way based on Before() function:

function Before(s, str: string): string;
var
p: Integer;
begin
if (Length(s) >= Length(str)) then
Exit;
p := Pos(s, str);
if (p > 1) then
Result := Copy(str, 1, (p - 1));
end;

var
str, user: string;

begin
ClearDebug;
str := 'Wizz Up has logged in.';
user := Before(' has logged in.', str);
WriteLn('User: "' + user + '"');
end.

That works without need for having TStringArray.

Runehack123

2013-03-30 11:31:35

^yes that way looks really nice