You need to sign in to do that
Don't have an account?
asadim
String repalce method doesn't seem to work properly
The replacement does not happen at all in this code. Any ideas why?!!
String res = //some very long string of length 72000 chars res = res.substring(4000, 5000); //this substring contains carriage return chars \n res = res.replaceAll('\n', ' '); system.debug(res);
Thanks in advanace!
Are you sure the \n isn't being escaped when you save it, or query it. It could be changed for <br> at some moment.
I did test your code an it worked well, so i think the problem is that the \n is being replaced on some instance before.
Ignacio.
All Answers
What I can suggest:
Use Encodingutil.urlEncode(str, 'UTF-8');
'\n' shall be converted to '%0D%0A'
Replace it and than decode it.
Hope this help
Cheers,
Are you sure the \n isn't being escaped when you save it, or query it. It could be changed for <br> at some moment.
I did test your code an it worked well, so i think the problem is that the \n is being replaced on some instance before.
Ignacio.
If you type in the string manually it works. But if the initial string is coming from somewhere else it doesn't. In my case the string was coming from another server as a JSON string. I still don't understand what was going on. I fixed it using JavaScript eventually.