Reading data from excel , few cell values have double quotes. How to include the double quotes while reading

0 votes

In excel sheet, I have a column which contains query in this format "sel * from ABC;" . Users will have to give the query with double quotes like this as spark engine process the query in this format.

In java code how can i read this value as it as without excluding the double quotes.

Currently it is read as

"\"select * from ABC;\"" .

how can i make it to

 "select * from from ABC;"
May 7 in Java by Jyra
• 490 points
38 views

1 answer to this question.

0 votes
Best answer

Hi, @Jyra,

You can use one Java function that is Java String Replaceall(): This method finds all occurrences of a sequence of characters matching a regular expression and replaces them with the replacement string. At the end of the call, a new string is returned by the function.

public class Career {
    public static void main(String args[]) {
        String str = "\"select * from ABC;\""
        String str2 = str.replaceAll("\"","");

);

System.out.println(str2);
    }
}

I hope this will help you.

answered May 7 by Gitika
• 29,690 points

selected May 7 by Jyra
HI Gitika, the problem is different. In excel it self i give the query in quotes. While java reads this it reads in "\"select * from abc\"" . In excel i gave it as "select * from abc"  [ including quotes].

Fixed this problem. While replacing the backslash, we have to give replace.("\\\\",""). this worked.

Hi, @Jyra,

That's great that you came up with a solution. Bingo!!

Related Questions In Java

0 votes
1 answer

In Java, how to find out the min/max values from array of primitive data types?

import java.util.Arrays; import java.util.Collections; import org.apache.commons.lang.ArrayUtils; public class MinMaxValue { ...READ MORE

answered Jun 12, 2018 in Java by Daisy
• 8,090 points
183 views
0 votes
1 answer

How to read text files from the Classpath in Java?

InputStream in = this.getClass().getClassLoader().getResourceAsStream("TextFile.txt"); InputStream in = this.getClass().getResourceAsStream("/TextFile.txt"); package ...READ MORE

answered May 8, 2018 in Java by Akrati
• 3,150 points
933 views
0 votes
1 answer

How to refresh a JTable model after insert delete or update the data

In my opinion, you can notify your ...READ MORE

answered Oct 10, 2018 in Java by code.reaper12
• 3,470 points
6,176 views
+2 votes
1 answer

How do I ask the Selenium-WebDriver to wait for few seconds in Java?

There are two ways to wait: explicit ...READ MORE

answered Dec 19, 2018 in Java by Daisy
• 8,090 points

edited Dec 19, 2018 by Daisy 96 views
+5 votes
3 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,420 points

edited Nov 6, 2018 by Omkar 22,163 views
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,510 points
3,528 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,510 points
8,545 views
0 votes
1 answer

Selenium JARS(Java) missing from downloadable link

Nothing to worry about here. In the ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,510 points
1,556 views
0 votes
1 answer

Convert data in List<JsonNode> to Map <String,String> in Java

Hi, @Jyra, Basically, you can use the object mapper to ...READ MORE

answered Apr 7 in Java by Gitika
• 29,690 points
302 views
0 votes
2 answers

How to generate a class at runtime?

Yes, I recently met this library which ...READ MORE

answered Apr 15 in Java by Edureka
• 500 points
51 views