Solved

Splitting a string with “\”

Posted on 2006-07-16
6
234 Views
Last Modified: 2010-03-31
Hi,
I want to split this string

C:\e\a\f\e.rr

With splitter (“\”) but it is not accepting because it expects “\n” or “\t”?

I want to split to double the “\”. So, I want to replace each

\

By

\\

So, this string
C:\e\a\f\e.rr

Must be
C:\\e\a\\f\\e.rr
0
Comment
Question by:javamate06
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 9

Expert Comment

by:riaancornelius
ID: 17119850
string tmp = C:\e\a\f\e.rr;
tmp = tmp.replaceAll("\\", "\\\\");
0
 
LVL 9

Expert Comment

by:riaancornelius
ID: 17119851
\ is an escape character, so in a java string you need to use \\ instead of \. Rule of thumb is to just double the amount of backslashes you want.
0
 

Author Comment

by:javamate06
ID: 17119885
Thank you

Do you mean \ is equal to \\
?

because I tried

string tmp = C:\e\a\f\e.rr;
tmp = tmp.replaceAll("\\", "\\\\");

but it does NOT work.
0
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
LVL 9

Accepted Solution

by:
riaancornelius earned 25 total points
ID: 17119907
my mistake...

Where does the string "C:\e\a\f\e.rr" come from? Do you specify it? Because if you do, you need to specify it as "C:\\e\\a\\f\\e.rr" and then if you print it out you'll see "C:\e\a\f\e.rr"
0
 
LVL 9

Expert Comment

by:riaancornelius
ID: 17119911
and then when you split it you also use "\\".
0
 
LVL 14

Expert Comment

by:StillUnAware
ID: 17119914
Having this executed

    String tmp = "C:\\e\\a\\f\\e.rr";
    System.out.println(tmp); // tmp = C:\e\a\f\e.rr
    tmp = tmp.replaceAll("\\\\", "\\\\\\\\");
    System.out.println(tmp);

the result will be

    C:\e\a\f\e.rr
    C:\\e\\a\\f\\e.rr
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question