Let's say I have the following line:
s := 'This , is, the Delphi , World!';
I need the following output:
Result := 'This,is,the Delphi,World!';
Basically, I need a procedure that allows ALL occurrences of spaces ONLY if they appear before or after the char comma (which is my separator), leaving intact spaces between other words.
Any help is greatly appreciated.
What do you think of this decision?
function RemoveSpacesAroundDelimiter(var aString: string; aDelimiter: string): string; begin while AnsiContainsText(aString, aDelimiter + ' ') do begin aString := StringReplace(aString, ', ', aDelimiter, [rfReplaceAll, rfIgnoreCase]); end; while AnsiContainsText(aString, ' ' + aDelimiter) do begin aString := StringReplace(aString, ' ' + aDelimiter, aDelimiter, [rfReplaceAll, rfIgnoreCase]); end; Result := aString; end;
thanks
Fabio
string delphi
Fabio vitale
source share