How to extract a point separated number format from a string?
for example a string like this
a = 'ProductX credit 1.000'
how to to get only the 1.000 from that string?
Thank you kindly
You can use method split by space in ruby
a = 'ProductX credit 1.000'
a.split(" ").last
Result
"1.000"
Input
a='ProductX credit 1.000'
Code
p a.rpartition(/\s/).last
Output
"1.000"
Related
How can I use chumsky to get the three binary characters from a binary string? I can't figure out from the documentation how to do this.
I see now it's possible to use Repeated::exactly like this:
let digits = one_of::<_, _, Cheap<char>>("01")
.repeated().exactly(3)
.then_ignore(end())
.collect::<String>();
How does one specify the number of decimal places when outputting a string ?
For example, say I have the following:
var root3 = 1.73205080757;
And wish to output to two decimal places, how do I format the string, similar to how one does so in Java ?
doubles in dart have a method toStringAsFixed() which is easy to use:
If you have :
var root3 = 1.73205080757;
You can just do:
print(root3.toStringAsFixed(2));
Output:
1.73
I have a string containing 3 or 4 double numbers. what's the best way to extract them in an array of numbers?
First you have to find the numerals. You can use a RegExp pattern for that, say:
var doubleRE = RegExp(r"-?(?:\d*\.)?\d+(?:[eE][+-]?\d+)?");
Then you parse the resulting strings with double.parse. Something like:
var numbers = doubleRE.allMatches(input).map((m) => double.parse(m[0])).toList();
i have the string price that has a value with a number in it. I have code that extracts the number, I need help to figure out how to have another string (pricechar) with only the "k" in it
price="1k"
--pricechar=...
pricenum=string.match(price,"%d+")
You can extract all non-numeric characters, similar to how you do it for numbers:
pricechar = string.match(price,"[^%d]+")
To get both values at the same time:
pricenum, pricechar = string.match(price,"(%d+)(.*)")
I am using ruby on rails
I have
article.id = 509969989168Q000475601
I would like the output to be
article.id = 68Q000475601
basically want to get rid of all before it gets to 68Q
the numbers in front of the 68Q can be various length
is there a way to remove up to "68Q"
it will always be 68Q and Q is always the only Letter
is there a way to say remove all characters from 2 digits before "Q"
I'd use:
article.id[/68Q.*/]
Which will return everything from 68Q to the end of the string.
article.id.match(/68Q.+\z/)[0]
You can do this easily with the split method:
'68Q' + article.id.split('68Q')[1]
This splits the string into an array based on the delimiter you give it, then takes the second element of that array. For what it's worth though, #theTinMan's solution is far more elegant.