on 10-27-2023 8:46 AM
I want to replace last comma with 'and' in sap crystal report.
I tried 'replace' and 'instr' in formula but not getting desired output.
Below is the example
example:
Jack, roy, mark, rohit, andrew ....so on
I want to replace only the last comma i.e “rohit” and “andrew” and change it to the word “and”, so the string becomes:
Jack, roy, mark, rohit and andrew
Thanks in advance
Here's another way to do it that's not as complicated:
local stringvar myText := "Jack, roy, mark, rohit, andrew";
local NumberVar commaAt := InStrRev(myText, ",");
left(MyText, commaAt-1) + Replace(MyText, ",", " and", commaAt)
InStrRev starts at the end of the string to find the character or string you're looking for.
-Dell
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dell's solution is indeed nicer 🐵
Try something like this:
local stringvar myText := "Jack, roy, mark, rohit, andrew";
local stringvar array myArray := Split(myText, ", ");
local stringvar result := myArray[1];
local numbervar i;
For i := 2 to Ubound(myArray)-1 step 1 do
(
result := result + ", " + myArray[i];
);
result := result + " and " + myArray[Ubound(myArray)];
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
9 | |
8 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.