I read a text field form DB and display it using MESSAGE(MyText); Problem is when there are ‘%’ chars in string - thex are not displayed, but rather newline is diplayed. Is there any trick do do it quickly (like double %%)? Or do I have to write a code to replace all ‘%’ with ‘%1’ and use STRSUBSTNO(MyText,’%’);
Hallo ®obi please try MESSAGE(’%1’,MyText); br Josef Metz
No,no. I know that trick. Check this: MyText := ‘Discounts: A=5%, B=10%, C=15%’); MESSAGE(MyText); What I can do is to replace all ‘%’ in MyText with ‘%1’ and then use Message (with “BuiltIn” STRSUBSTNO). The code would be: MyText := ‘Discounts: A=5%1, B=10%1, C=15%1’); MESSAGE(MyText,’%’); As converting MyText requires some lines of code I thought if there is more elegant solution ?
From the archives (in case you do need the small function): ReplaceString(String : Text[250];FindWhat : Text[250];ReplaceWith : Text[250]) NewString : Text[250] WHILE STRPOS(String,FindWhat) > 0 DO String := DELSTR(String,STRPOS(String,FindWhat)) + ReplaceWith + COPYSTR(String,STRPOS(String,FindWhat) + STRLEN(FindWhat)); NewString := String;
Hallo ®obi, i don’t know, if i understand your problem. i have testet the following code in Ver 2.60 and Ver. 3.70: MyText := ‘Discounts: A=5%, B=10%, C=15%’; MESSAGE(’%1’,MyText); and both version show ‘Discounts: A=5%, B=10%, C=15%’ on the screen. The first parameter of the MESSAGE is a format-string with % and a number as a placeholder and the other parameters are the values for the placeholders, but they are not required. br Josef Metz
Josef, only now I noticed what are you trying to say. Yes it works (displays %). …although I had to make some other adjustments, since MyText includes also ‘’ that I do want to use for newlines. Since I’m manually concatenating MyText from many strings I know exactlly were ‘’ is positioned. I used: ch13 := 13; MyText := MyText + FORMAT(ch13) + LineOfText; instead of MyText := MyText + ‘’ + LineOfText;
quote:
Originally posted by nelson
From the archives (in case you do need the small function):ReplaceString(String : Text[250];FindWhat : Text[250];ReplaceWith : Text[250]) NewString : Text[250] WHILE STRPOS(String,FindWhat) > 0 DO String := DELSTR(String,STRPOS(String,FindWhat)) + ReplaceWith + COPYSTR(String,STRPOS(String,FindWhat) + STRLEN(FindWhat)); NewString := String;
Nelson thanks, but this function has some bugs. It ends in endless loop if: FindWhat is found in ReplaceWith (in my case ‘%’ and ‘%1’ or try ‘AB’, ‘ABC’) Here’s (I hope) bug-free function: TextReplace(ltInput : Text[1024];ltWhat : Text[1024];ltWith : Text[1024]) ltOutput : Text[1024] liFirstPos := STRPOS(ltInput,ltWhat); WHILE (liFirstPos > 0) DO BEGIN ltOutput := ltOutput + COPYSTR(ltInput,1,liFirstPos - 1) + ltWith; ltInput := COPYSTR(ltInput,liFirstPos + STRLEN(ltWhat)); liFirstPos := STRPOS(ltInput, ltWhat); END; ltOutput := ltOutput + ltInput;
No need for ch13 really. Try this:TXT1 := 'C:\DRIVE '; TXT2 := '100% '; TXT3 := 'D:\DRIVE\ '; MESSAGE('Rubbish: ' + TXT1 + TXT2 + TXT3); MESSAGE('Ok1: %1 %2 %3', TXT1, TXT2, TXT3); MESSAGE('Ok2: %1 %2\%3', TXT1, TXT2, TXT3);