
Originally Posted by
Kik
Mkay, so I'm making a trading function that uses the traders name with some other stuff (might release eventually), and I need some help.
1)Any way to make a string into an array of char?
2) to find if a single char is part of a string, like see if there is an 'e' in a certain word.
3)Make a nickname out of a string, like take the middle 3 letters?
Thanks in advance.
for #1)
Kinda confused? Do you mean like so the string 'Hello' would be returned as an array of ['H', 'e', 'l', 'l', 'o']?
If so I made these:
SCAR Code:
Function StringToCharArray(TheString: string): TStringArray;
var
i : Integer;
begin
for i := 1 to Length(TheString) do
begin
SetLength(Result, i);
Result[i - 1] := copy(TheString, i , 1);
end;
end;
//EXAMPLE of use:
begin
WriteLn(BoolToStr(InStrArr('o', StringToCharArray('hello'), False)));
//will say if the letter 'o' is found in the array of chars made by the function StringToCharArray('hello')
end.
for #2)
Maybe use:
PHP Code:
function pos(substr, s: string): LongInt;
Returns position of substring in string. Returns 0 if not found.
Example:
SCAR Code:
begin
TheString := 'Bobby';
if not (pos('o', TheString)=0) then //if 'o' IS in the TheString then..
if (pos('o', TheString)=0) then //if 'o' IS NOT in the TheString then..
end.
for #3)
Maybe use:
PHP Code:
function copy(s: string; ifrom, icount: LongInt): string;
Returns part of the string (Copy('abcde',2,3) would return 'bcd'.
Example:
SCAR Code:
begin
TheString := 'Bobby';
Nickname := Copy(TheString, 2, 3);
//would make nickname 'obb'
end.
Hope this helps =]
Derek-