Questions tagged [string-parsing]

The action of retrieving data from a string

String parsing is the action of extracting or modifying data pieces from a string. For example, one might parse a string to remove all quotation marks or to find all items inside quotation marks.

943 questions
3567
votes
79 answers

How to validate an email address using a regular expression?

Over the years I have slowly developed a regular expression that validates MOST email addresses correctly, assuming they don't use an IP address as the server part. I use it in several PHP programs, and it works most of the time. However, from time…
acrosman
  • 12,375
  • 10
  • 36
  • 54
163
votes
8 answers

Safe integer parsing in Ruby

I have a string, say '123', and I want to convert it to the integer 123. I know you can simply do some_string.to_i, but that converts 'lolipops' to 0, which is not the effect I have in mind. I want it to blow up in my face when I try to convert…
wvdschel
  • 11,590
  • 14
  • 38
  • 44
102
votes
22 answers

Convert String to Float in Swift

I'm trying to convert numbers taken from a UITextField, which I presume, are actually Strings, and convert them to Float, so I can multiply them. I have two UITextfields which are declared as follows: @IBOutlet var wage: UITextField @IBOutlet var…
Stephen Fox
  • 12,750
  • 19
  • 46
  • 51
97
votes
2 answers

How do I parse a URL query parameters, in Javascript?

Possible Duplicate: Use the get paramater of the url in javascript How can I get query string values in JavaScript? In Javascript, how can I get the parameters of a URL string (not the current URL)? like: www.domain.com/?v=123&p=hello Can I get…
user847495
  • 8,403
  • 15
  • 42
  • 47
59
votes
2 answers

How do I search for a pattern within a text file using Python combining regex & string/file operations and store instances of the pattern?

So essentially I'm looking for specifically a 4 digit code within two angle brackets within a text file. I know that I need to open the text file and then parse line by line, but I am not sure the best way to go about structuring my code after…
Carl Carlson
  • 778
  • 1
  • 6
  • 17
58
votes
12 answers

Convert String with Dot or Comma as decimal separator to number in JavaScript

An input element contains numbers a where comma or dot is used as decimal separator and space may be used to group thousands like this: '1,2' '110 000,23' '100 1.23' How would one convert them to a float number in the browser using…
Andrus
  • 22,189
  • 50
  • 171
  • 330
48
votes
4 answers

Parse time of format hh:mm:ss

How can I parse a time of format hh:mm:ss , inputted as a string to obtain only the integer values (ignoring the colons) in java?
user1604288
  • 655
  • 1
  • 5
  • 7
42
votes
5 answers

Get contents after last slash

I have strings that have a directory in the following format: C://hello//world How would I extract everything after the last / character (world)?
john cs
  • 2,024
  • 5
  • 26
  • 45
40
votes
15 answers

How to Convert Persian Digits in variable to English Digits Using Culture?

I want to change persian numbers which are saved in variable like this : string Value="۱۰۳۶۷۵۱"; to string Value="1036751"; How can I use easy way like culture info to do this please? my sample code is: List NERKHCOlist = new…
Amin AmiriDarban
  • 1,769
  • 4
  • 20
  • 29
36
votes
5 answers

Long.getLong() failing, returning null to valid string

I've spent the past two hours debugging what seems extremely unlikely. I've stripped the method of a secondary Android Activity to exactly this: public void onClick(View v) { String str = "25"; long my_long = Long.getLong(str); } //…
SMBiggs
  • 9,090
  • 4
  • 54
  • 69
32
votes
2 answers

Get number of characters read by sscanf?

I'm parsing a string (a char*) and I'm using sscanf to parse numbers from the string into doubles, like so: // char* expression; double value = 0; sscanf(expression, "%lf", &value); This works great, but I would then like to continue parsing the…
Alexis King
  • 40,717
  • 14
  • 119
  • 194
30
votes
16 answers

How to separate full name string into firstname and lastname string?

I need some help with this, I have a fullname string and what I need to do is separate and use this fullname string as firstname and lastname separately.
user773456
  • 513
  • 2
  • 8
  • 14
30
votes
5 answers

Code to parse user agent string?

As strange as I find this, I have not been able to find a good PHP function anywhere which will do an intelligent parse of a user agent string? Googled it for about 20 minutes now. I have the string already, I just need something that will chop it…
Spot
  • 7,407
  • 9
  • 41
  • 55
28
votes
13 answers

How do I extract a substring from a string until the second space is encountered?

I have a string like this: "o1 1232.5467 1232.5467 1232.5467 1232.5467 1232.5467 1232.5467" How do I extract only "o1 1232.5467"? The number of characters to be extracted are not the same always. Hence, I want to only extract until the second space…
gbprithvi
  • 281
  • 1
  • 3
  • 3
24
votes
15 answers

Determine if a String is a number and convert in Java?

I know variants of this question have been asked frequently before (see here and here for instance), but this is not an exact duplicate of those. I would like to check if a String is a number, and if so I would like to store it as a double. There…
Michael McGowan
  • 6,313
  • 6
  • 37
  • 69
1
2 3
62 63