Hi all, I would like to replace the last space of a string and put a new character. eg: from "Test something 1" to "Test something, 1"... I tried with some convertstr, delchr functions but nothing worked.. any idea? Thank you...
ok, I'm done with that, the last doubt is how can I replace a part of a string?
e.g.
String -> hello world
search -> wo
replace with -> WO
result -> hello WOrld
there is no function such, in this case I think You need to make Your own function
can be like this
LastSpacePos(Tstr : Text[30]) SpacePos : Integer
SpacePos:=STRPOS(Tstr,' ');
IF SpacePos = 0 THEN EXIT(0);
Tstr:=COPYSTR(Tstr,SpacePos+1,30);
WHILE STRPOS(Tstr,' ')>0 DO BEGIN
SpacePos:=SpacePos+STRPOS(Tstr,' ');
Tstr:=COPYSTR(Tstr,STRPOS(Tstr,' ')+1,30);
END;
so if there are no spaces in Tstr then return 0 like STRPOS (built-in function)
You can add also a second parameter that will find any character and return last position in string
Answers
e.g.
String -> hello world
search -> wo
replace with -> WO
result -> hello WOrld
'mscorlib, Version=4.0.0.0, Culture=neutral,PublicKeyToken=b77a5c561934e089'.System.String
...then use the Replace method...
MyDotNetString := ‘hello world’;
MyDotNetString := MyDotNetString.Replace(‘wo’,’WO’);
can be like this
LastSpacePos(Tstr : Text[30]) SpacePos : Integer
SpacePos:=STRPOS(Tstr,' ');
IF SpacePos = 0 THEN EXIT(0);
Tstr:=COPYSTR(Tstr,SpacePos+1,30);
WHILE STRPOS(Tstr,' ')>0 DO BEGIN
SpacePos:=SpacePos+STRPOS(Tstr,' ');
Tstr:=COPYSTR(Tstr,STRPOS(Tstr,' ')+1,30);
END;
so if there are no spaces in Tstr then return 0 like STRPOS (built-in function)
You can add also a second parameter that will find any character and return last position in string