+ Start a Discussion
CB312CB312 

Unterminated string literal - removing the new line from a Long Text Area '/n'

Hey All,

 

Is there a way to remove the new line character '/n' from a Long Text Area in Apex? I am trying to pass to a google fusion obj and they don't handle the '/n' character and throw an exception. Any idea how I can take a long text area(we will call it LT__c) and have it remove the new line characters? Is this supported nativly in apex?

 

Thanks!

-Chris

vhanson222vhanson222

You should be able to use the replaceAll method to accomplish that:

 

String someText = CutomObject__c.LongTextArea__c;
// replace carriage returns with the HTML equivalent
return someText.replaceAll('\n','<br/>');

 

 

Ayub AnsariAyub Ansari
I dont know previously it was supported or not, but now a days the best way is:

string = string.unescapeJava();