You need to sign in to do that
Don't have an account?
Dilyan Dimitrov
Apex can not remove multiple spaces in String
Hello,
I am trying to remove all spaces from the following string:
At the moment I'm using the following source code:
Regards,
Dilyan
I am trying to remove all spaces from the following string:
howabountnow.com,,,itsme.com,,,name,,,hello.com,,,asdasdasdasd.asdasdasda,: :: :;; ;;; :: :: :; ; ;,, ,,, ,,, asdasd.asd,,, ,,,asdsadas,,,dilyanand from the place where there are multiple spaces it is removed only one space and the result is:
DEBUG|domain1 howabountnow.com,,,itsme.com,,,name,,,hello.com,,,asdasdasdasd.asdasdasda,::::;; ;;;:: :::;;;,,,,,,,,asdasd.asd,,,,,,asdsadas,,,dilyanSo far I've tried the following:
replaceAll('\s+', ''); replaceAll('[ ]+', ''); replace(' ', '');and few more similar expressions.
At the moment I'm using the following source code:
String domain = accountObj.Domain__c; System.debug('domain ' + domain); integer spaceInd = domain.indexOf(' '); System.debug('spaceInd1: ' + spaceInd); while (spaceInd > -1) { domain = domain.replace(' ', ''); spaceInd = domain.indexOf(' '); System.debug('spaceInd: ' + spaceInd); } System.debug('domain1 ' + domain);When I start the code in debug log I get the following:
USER_DEBUG|[198]|DEBUG|domain howabountnow.com,,,itsme.com,,,name,,,hello.com,,,asdasdasdasd.asdasdasda,: :: :;; ;;; :: :: :; ; ;,, ,,, ,,, asdasd.asd,,, ,,,asdsadas,,,dilyan USER_DEBUG|[203]|DEBUG|spaceInd1: 75 USER_DEBUG|[207]|DEBUG|spaceInd: -1 USER_DEBUG|[209]|DEBUG|domain1 howabountnow.com,,,itsme.com,,,name,,,hello.com,,,asdasdasdasd.asdasdasda,::::;; ;;;:: :::;;;,,,,,,,,asdasd.asd,,,,,,asdsadas,,,dilyanCould you please advise how to remove all spaces from the String or replace them with a single space in apex?
Regards,
Dilyan
KevinP
Use this Regualr Expression: /\s{1,}/ that says substrings of 1 or more spaces.
Frédéric Provot
myString.deleteWhitespace()