function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

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?





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();