java - How to replace an escape char? -
i'm trying sanitize/standardize user input file directories. windows \
, *nux/*nix /
. in java \
must escaped \\
otherwise compile error.
how can read \
user input , replace /
?
private string escapedirs(string raw) { return raw.replace("\\", "/"); }
this not work... presumably because it's read in \
not \\
. can't raw.replace("\", "/");
...
sample user input: c:\user\someuser\somedir
if building solution windows , unix both 1 of issues developer need take care
there 2 approaches
handle escape characters windows seperately using \ , paths unix seperately
use / in paths windows , same used in unix , windows
example
in windows
c:/temp works same c:\temp
in unix
/tmp/
hope helps
thanks abhi
Comments
Post a Comment