chkaufmann 17 Posted May 15, 2019 I need a function like stripcslashes() in PHP. Is there something similar in Delphi or do I have to write it on my own. Christian Share this post Link to post
Leif Uneus 43 Posted May 15, 2019 ExcludeTrailingPathDelimiter http://docwiki.embarcadero.com/Libraries/en/System.SysUtils.ExcludeTrailingPathDelimiter Share this post Link to post
PeterBelow 238 Posted May 15, 2019 10 minutes ago, chkaufmann said: I need a function like stripcslashes() in PHP. Is there something similar in Delphi or do I have to write it on my own. Christian The PHP function converts escaped characters like \n to their actual character (chr(13) in this case), no? Delphi has nothing like that since there is no need to escape characters in Delphi strings, they are all UTF-16 by default. So you have to write your own, I think. Share this post Link to post
chkaufmann 17 Posted May 15, 2019 Yes, that's what I need. Convert \n and \t to chr(10) and chr(9). Treating the string as array is this fine? Or is there a faster way to do it? Something like this n := ASource.Length; SetLength(Result, n); ix1 := 1; ix2 := 1; while ix1 <= n do begin if ASource[ix1] = '\' then begin Inc(ix1); case ASource[ix1] of 't': Result[ix2] := chr(9); 'n': Result[ix2] := chr(10); '\': Result[ix2] := '\'; end; end else Result[ix2] := ASource[ix1]; Inc(ix1); Inc(ix2); end; if ix1 <> ix2 then SetLength(Result, ix2 - 1); Christian Share this post Link to post
Uwe Raabe 2057 Posted May 15, 2019 Result := ASource.Replace('\n', #10).Replace('\t', #9); Perhaps not the fastest approach, but pretty simple:. Share this post Link to post
Sherlock 663 Posted May 16, 2019 22 hours ago, Uwe Raabe said: Perhaps not the fastest approach, but pretty simple:. KISS rules! Share this post Link to post
Dmitry Arefiev 101 Posted May 16, 2019 May be a bit unexpected approach. And sorry not C but JS, but they are close here. uses System.JSON; function StripJSSlashes(const AStr: string): string; var LVal: TJSONValue; begin LVal := TJSONObject.ParseJSONValue('"' + AStr + '"', False, True); try Result := TJSONString(LVal).Value; finally LVal.Free; end; end; Share this post Link to post