Skip to main content
2 of 3
added 3 characters in body

String function cannot read white spaces

I have following code :

     `for(String s:valuearray){
        String s9 = s;
        system.debug('startvalue!!'+s9+'******'+s9.remove(' '));
        List<String> li = s.split(';');
        system.debug('li----'+li);
       
        System.debug('test%%%%%%%%%'+li[0]+'**'+li[0].deleteWhitespace());
       
       
        system.debug('no of whitespace--'+li[0].countMatches(' '));
       
        
       
        Decimal d = Decimal.valueof(li[0].deleteWhitespace());
        if(li[1] != '')
            m.put(li[1],d); 
        singtotal = singtotal +d;          
    }`

ValueArray is coming as an array of string from Javascript function in a Lightning component. This code removes whitespaces the first time loop runs(e.g first string in valueArray is '12 000;Q1'). The next time loop runs(eg second string in valueArray is '80 000 000 000;Q2'), it does not read the whitespace, neither does it remove it. Apart from deletewhitespace(),I tried to use replace(), replaceAll(). I tried to use containswhitespace() to check if it is reading the whitespaces or not, but everything works for the first run. What can be the issue.