function IndexOfChar( S, ' '); r:=s-IndexOfChar; laststring:=сору(s,IndexOfChar,r) EditN.Caption:=laststring;
Here we copy the entire line after the character (space). How to copy only the second word? Ie the word after the space.
function IndexOfChar( S, ' '); r:=s-IndexOfChar; laststring:=сору(s,IndexOfChar,r) EditN.Caption:=laststring;
Here we copy the entire line after the character (space). How to copy only the second word? Ie the word after the space.
If, I understood correctly, then you need to copy only the second word from the source line, and the words are separated by spaces, here's the code:
procedure TForm1.Button1Click (Sender: TObject); Var SS, S: String; begin SS: = Edit1.Text; S: = Copy (SS, Pos ('', SS) +1, Length (SS) -Pos ('', SS)); If (Pos ('', S)> 0) Then S: = Copy (S, 1, Pos (", S) -1); Edit2.Text: = S; end;
AnsiPos
. - SoftRHere is my version of the function that returns the word you need:
Function WordFromIndex (s:string;I:integer):String; Var sl:TStringList; begin sl:=TstringList.Create; s:=StringReplace(s,#32,#13,[rfReplaceAll, rfIgnoreCase]); sl.Clear; sl.Text:=s; Result:=sl.Strings[i-1]; sl.Free; end;
Use this:
WordFromIndex (s,i);
Where S
is a string is long, and I
is the number of a word in a string, the result will be a word.
PS Immediately I warn you, wrote just like that, a lot is not taken into account. It is assumed that the line does not begin with a space, that there is strictly one space between words, etc. I just showed another solution to the problem.
Source: https://ru.stackoverflow.com/questions/40837/
All Articles