lstIQCodes = IQcodeString.replaceAll(' ','').split(',');
I have tried the above code and able to replace spaces and now I want to replace newline as well.
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.Sign up to join this community
If you just want to get rid of all the white space, you can just delete it:
lstIQCodes = IQcodeString.deleteWhitespace().split(',');
ReplaceAll actually takes a regular expression for the first parameter, so the following is also valid:
lstIQCodes = IQcodeString.replaceAll('\\s+','').split(',');
\\s refers to all white space, including tabs, new lines, carriage returns, and spaces.
Or, if you really just wanted spaces and newlines:
lstIQCodes = IQcodeString.replaceAll('[\\n ]+','').split(',');