Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I know that "\" is an escape character, but is there really no possibility to read it as a "normal" character?

I wanted to read a path (which is read out in a string) character by character and check whether one is a backslash.. but that only works if i put double backslashes in the path.

Hope you can help me!
Posted

Java
String slash = "\\";

There's no alternatives.
 
Share this answer
 
v2
Comments
epanjohura 10-Oct-11 2:20am    
that also doesn't work, but I think I found the problem :)
André Kraak 10-Oct-11 2:33am    
If you have found the solution please post it as a solution here, so that anyone with a similar problem can use it.
Thank you.
epanjohura 10-Oct-11 2:34am    
yes of course I'll post it here, I'm just trying if this works :)
epanjohura 12-Oct-11 1:42am    
I found a solution ;)
My Solution:

First I used
import java.util.Properties;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java io.IOException;

and loaded the file with
private static String InFile;
String Path;

Properties props = new Properties();
FileInputStream in = null;

// create input stream to read file
try{
    in = new FileInputStream(new File(Path));
} catch(FileNotFoundException e1) {
    ErrorHandling.printError("Error");
}

try{
    props.load(in);
} catch(IOException e) {
    ErrorHandling.printError("Error");
}

I got my path by searching in file by a key word p.E.
InFile = props.getProperty("Path=");

and thats not a good idea for that what I did.
As I said, I wanted to check if there is any backslash in the path, if yes then add another backslash.
Well, that's what I did instead of using this properies:
import java.util.Scanner;
import java.io.FileReader;

String Lines = null;

FileReader fr = new FileReader(Path);
Scanner input = new Scanner(fr);

// read out each line of file
while(input.hasNextLine())
{
    Lines = input.nextLine();
    System.out.println(Lines);
}


I hope everyone understand what I'm trying to explain :)


Painjofshem
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900