

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to remove the leading and trailing quotes from a string
Firstly, let us consider a string with quotes
String originalStr = "\"Demo Text\"";
Now, consider the following logic for the beginning quote.
if (originalStr.startsWith("\"")) { originalStr = originalStr.substring(1, originalStr.length()); }
Now, consider the following logic for the ending quote.
if (originalStr.endsWith("\"")) { originalStr = originalStr.substring(0, originalStr.length() - 1); }
Example
public class Demo { public static void main(String[] args) { String originalStr = "\"Demo Text\""; System.out.println("String with double quotes= "+originalStr); if (originalStr.startsWith("\"")) { originalStr = originalStr.substring(1, originalStr.length()); } if (originalStr.endsWith("\"")) { originalStr = originalStr.substring(0, originalStr.length() - 1); } System.out.println("String after removing double quotes = "+originalStr); } }
Output
String with double quotes= "Demo Text" String after removing double quotes = Demo Text
- Related Questions & Answers
- Java Program to remove leading and trailing whitespace from a string
- Trim a string in Java to remove leading and trailing spaces
- Trim (Remove leading and trailing spaces) a string in C#
- How to remove white spaces (leading and trailing) from string value in MongoDB?
- How to remove leading and trailing whitespace from a MySQL field value?
- How to remove all trailing and leading whitespace in a string in Python?
- Remove Leading Zeros From String in Java
- How to remove leading and trailing whitespace in a MySQL field?
- Explain how to remove Leading Zeroes from a String in Java
- Python Pandas – Remove leading and trailing whitespace from more than one column
- Java Program to Remove leading zeros
- Remove Leading Zeros from a String in C#
- Remove Leading Zeroes from a String in Java using regular expressions
- How can we eradicate leading and trailing space characters from a string in MySQL?
- How can I remove the leading and trailing spaces both at once from a string by using MySQL LTRIM() and RTRIM() functions?
Advertisements