0

I having a text like Apple|MicroSoft|Oracle|Windows|Mac|.I wish to print like Apple Microsoft Oracle Windows Mac.

I used .split() keword, but it prints like, A p p l e | M i c r o s o f t | ...

why it will print like this if any alternate solution for this. Thanks in advance.

1
  • Show the code you're trying to use. Commented Aug 6, 2011 at 6:42

3 Answers 3

3

This should work:

String name = "Apple|MicroSoft|Oracle|Windows|Mac|";
name = name.replaceAll("\\|", " ");
Sign up to request clarification or add additional context in comments.

Comments

2

For this particular example, just use replace() to switch out the | characters with spaces

3 Comments

i cant change the | with space because it related with another Operation
@BenDennison: I meant using the replace() method, not changing it in the original string
@Ben, why not? Pepsi's algorithm gives exactly what you asked for: yourString.replaceAll("|", " ")
0

If using the split() function, try .split("|")

3 Comments

ya, i already used this will i'm using .split("|") it prints like this A p p l e |
ya, i already use this, while i using this it prints like this, A P P L E | M I C R O S O F T...
If you split on the pipe then you will have to join with a space. It's better to do the replaceAll.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.