How can I trim beginning and ending double quotes from a string?
You can use String#replaceAll()
with a pattern of ^\"|\"$
for this.
E.g.
string = string.replaceAll("^\"|\"$", "");
To learn more about regular expressions, have al ook at http://regular-expression.info.
That said, this smells a bit like that you're trying to invent a CSV parser. If so, I'd suggest to look around for existing libraries, such as OpenCSV.
Remove quotes from String in Python
Just use string methods .replace()
if they occur throughout, or .strip()
if they only occur at the start and/or finish:
a = '"sajdkasjdsak" "asdasdasds"'
a = a.replace('"', '')
'sajdkasjdsak asdasdasds'
# or, if they only occur at start and end...
a = a.strip('\"')
'sajdkasjdsak" "asdasdasds'
# or, if they only occur at start...
a = a.lstrip('\"')
# or, if they only occur at end...
a = a.rstrip('\"')
Removing the double quotes from a string
Try this...
Dim s as String = "['C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB01.JPG';'C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB02.JPG']"
s = s.Replace("'", "").Trim()
Any character or word or phrase or even a sentence is considered a string when it's enclosed in double quotes, but if the value of your string literally has double quotes, like this "SAMPLE", and you want to remove the double quotes, then do something...
Dim s as String = ""['C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB01.JPG';'C:\Users\Elvin Gentiles\Desktop\RiceLAB\BLB02.JPG']""
s = s.Replace("""", "").Trim()
Yes I noticed...double double quotes...I equated s to something that you say is passed from MATLAB, the string literally has double quotes, so to remove this, you replace double double quotes with nothing. That's how you do it in .NET. Your compiler interprets double double quotes as just a single quote :)
How can I remove double quotes from a string
Supposed you have
var currntDate = @"""'2017-08-03'""";
Just use
currntDate = currntDate.Replace("\"","");
How to remove double quotes from list of strings?
Try this:
VERSION = ["'pilot-2'", "'pilot-1'"]
VERSIONS_F = []
for item in VERSION:
temp = item.replace("'",'')
VERSIONS_F.append(temp)
print (VERSIONS_F)
it will print ['pilot-2','pilot-1']
Related Topics
Rails Script Segmentation Fault with Rvm
Rails 4 Devise 3.1.1 Actioncontroller::Unknownformat in Devise::Registrationscontroller#New
Colorized Output Breaks Linewrapping with Readline
Script to Run Against Stdin If No Arg; Otherwise Input File =Argv[0]
How to Extend Redcarpet to Support Auto Linking User Mentions
Troubles with Ruby-2.X Installation Using Rvm
What Is the Most Ruby-Ish Way of Accessing Nested Hash Values at Arbitrary Depths
Rails: How to to Download a File from a Http and Save It into Database
Cannot Load Such File -- Rack/Handler/Puma
Extract All Urls Inside a String in Ruby
Understanding Precedence of Assignment and Logical Operator in Ruby
Rails/Activerecord: Save Changes to a Model's Associated Collections
Sign Out Specific User with Devise in Rails
Ruby on Rails:Rails Generate Controller Does Not Work
Error Running Heckle? 'Current_Code': Undefined Method 'Translate' for Ruby2Ruby