How do I detect and remove "\n" from given string in action script?

actionscript-3

Solution

There are a few cases that the line-end marking may be: CRLF, CR, LF, LFCR. Possibly your string contains CRLF for line endings instead of only LF (\n). And so, with all the LFs removed, some text editors will still treat CRs as line-end characters.

Try this instead:

//this function requires AS3
public static function clearDelimeters(formattedString:String):String {     
  return formattedString.replace(/[\u000d\u000a\u0008\u0020]+/g,""); 
}

Note that \t is for tab, it's not space. Or if you're working with HTML, <br> and <br/> are used to make line breaks in HTML but they are not line-end characters.

Problem

I have the following code, ``` public static function clearDelimeters(formattedString:String):String { return formattedString.split("\n").join("").split("\t").join(""); } ``` The spaces i.e. "\t" are removed but the newline "\n" are not removed from the formattedString. I even tried ``` public static function clearDelimeters(formattedString:String):String { var formattedStringChar:String = ""; var originalString:String = ""; var j:int = 0; while((formattedStringChar = formattedString.charAt(j)) != "") { if(formattedStringChar == "\t" || formattedStringChar == "\n") { j++; } else { originalString = originalString + formattedString; } j++; } return originalString; } ``` This also didn't work. Expected help is the reason why newline delimeters are not removed and some way to remove the newline. Thank you in anticipation

Original source