Find your content:

Search form

You are here

New string methods substring Before/After, etc


I'm playing with the new string toys. I'm getting something out of a CSV (and I have very good reason to need to do that).

I tried this: contents = contents.substringAfter('/n') and it's not finding anything. I know I have lots of '/n' in my file because contents.split('n', 2) throws up because the regex is too complicated.

Is there something I should be using instead of /n to denote a new line in a text file?

Attribution to: Shane McLaughlin

Possible Suggestion/Solution #1

A newline is most commonly denoted by the escape character \n and not /n However, with CSV's, you may also want to check for \r\n as it will depend on the Operating System that is saving the file. Difference between '\n' and '\r\n'

string testString = 'Hello\nWorld';

16:43:16:021 USER_DEBUG [2]|DEBUG|World

Attribution to: Mikey
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content