Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

Unicode non-breaking space is not considered white space?

Asked by Benjamin Moore Jul 3, 2021 2.5K views 1 answer
Share

About this question

Can anyone confirm that Unicode u00A0 non-breaking space is not considered "whitespace" by Apex and is not detected by trim(), deleteWhitespace, or regex? I'm surprised by regex since I thought s was supposed to include non-breaking spaces. Of the methods below, only replaceAll with the character code works.

String x = 'u00A0' + 'Test'; String y = x.unescapeUnicode(); system.debug('### y trim length: ' + y.trim().length()); system.debug('### y deleteWhitespace length: ' + y.deleteWhitespace().length()); system.debug('### y replaceall regex length: ' + y.replaceAll('\s', '').length()); system.debug('### y replaceall unicode length: ' + y.replaceAll('\u00A0', '').length());


Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.