2

I have a CSV file which displays a name followed by 3 integers as shown below.

"John","12","37","1000"

I have the 3 number values indexed as values[1], values[2] and values[3].

I am trying to parse the strings from the CSV file by using the following:

int wins = Integer.parseInt(values[1]);
int losses = Integer.parseInt(values[2]);
int money = Integer.parseInt(values[3]);

My problem is that the values in the CSV file already are surrounded by " ", so when I try to parse the string it is trying to parse ""12"", ""37"" and ""1000"".

Is there any way in which I could ignore the " " in the CSV file without deleting them manually in the file?

3 Answers 3

2

You could use str.replace("\"","") to replace all the " in the string.

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

1 Comment

My mistake it should be replace!
1

You could take the substring between the quotes

values[1].substring(1, values[1].length() - 1)

Comments

0

You can use String.substring(int, int) method.

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.