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
DannyK89DannyK89 

String Split

OK so I was trying to split a string with a space in the middle of the string. I use: String [] NewString = tempname.split('\\ '); am I doing something wrong or does this just not work for spaces.

Best Answer chosen by Admin (Salesforce Developers) 
apex_keenapex_keen

It seems you're escaping the white spaces which is not needed. I tried this and it is working

 

                String S = 'boo and foo';
                list<string> lstr = S.split(' ') ; ( just a space in middle of quotes here )
                system.debug(lstr.get(2));

 

Giving correct result , which is foo