0

I have one string and I want to split it into substring in Java, originally the string is like this

Node( <http://www.mooney.net/geo#wisconsin> )

Now I want to split it into substring by (#), and this is my code for doing it

String[] split = row.split("#");

String word = split[1].trim().substring(0, (split[1].length() -1));

Now this code is working but it gives me

    "wisconsin>"

the last work what I want is just the work "wisconsin" without ">" this sign, if someone have an idea please help me, thanks in advance.

0

6 Answers 6

6

Java1.7 DOC for String class

Actually it gives you output as "wisconsin> " (include space)

Make subString() as

String word = split[1].trim().substring(0, (split[1].length()-3));

Then you will get output as

wisconsin

Tutorials Point String subString() method reference

Sign up to request clarification or add additional context in comments.

Comments

1

Consider

String split[] = row.split("#|<|>");

which delivers a String array like this,

{"http://www.mooney.net/geo", "wisconsin"}

Get the last element, at index split.length()-1.

Comments

1

String string = "Enter parts here";

String[] parts = string.split("-");

String part1 = parts[0];

String part2 = parts[1];

1 Comment

Welcome to stackoverflow! Please use markdown to format your code, otherwise it is harder to understand. More info: stackoverflow.com/editing-help
0

you can just split like you did before once more (with > instead of #) and use the element [0] istead of [1]

Comments

-1

You can just use replace like.

word.replace(char oldChar, char newChar)

Hope that helps

Comments

-1

You can use Java String Class's subString() method.

Refer to this link.

Comments

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.