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

  1. handle escape characters windows seperately using \ , paths unix seperately

  2. 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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -