I have this sample string:
"TRYU MTH INCOME=3400.00 20%INCOME=680.00 NAV MPA=439.02 OTHER MPA=580.00"
I would like to test if the label "20%INCOME" exists in this string and if it does return the corresponding dollar value (680.00) and put it into a variable. In practice, the dollar values will change (larger and smaller) so therefore they are never in the same position within the string. Any help with this would be much appreciated.
Thanks
Related
Can someone please help me with how can a string value be converted into a predefined format by splitting the string?
For example:
If the
Stringvalue = "20210819"
needs to be converted as "08/19/2021"
(Splitting first four and then next two and again next two)
Thanks,
Thanks, #DaveNewton, I was able to do that as you suggested.
Stringvalue = "20210819"
valuedate=Stringvalue
valueyear=(valuedate[0..3]);
valuemonth=(valuedate[4..5]);
valueday=(valuedate[6..7]);
println (valuemonth+"/"+valueday+"/"+valueyear);
I have a list of strings [abc1, abc2, abc3, xyz3, xyz4]
Out of the elements with the same string preceding the number, I need to keep just the string with the highest number in my output list. So out of abc1, abc2 and abc3, the string abc3 should be selected. Out of xyz3 and xyz4, xyz4 should be kept.
So the final list should contain [abc3, xyz4].
I've been thinking of how this problem can be solved since the past 2 days and after unsuccessfully trying out some approaches, I am still in the dark how this can be done. I would greatly appreciate any help on this.
This function is what you need
The first step of each item is divided into two parts, number and string
Step 2 If the aphid already exists in the dictionary, its value is compared to the current item value. If it is smaller, its value is moved to the current number.
Otherwise I save the value in the dictionary.
Finally, we turn the dictionary into a list
def split(items):
biggest=dict()
for i in items:
string = i[:-1]
number = int(i[-1])
if string in biggest:
if biggest[string]<number:
biggest[string]=number
else:
biggest[string]=number
return list([k+str(v) for k,v in biggest.items()])
x = ['abc1', 'abc2', 'abc3', 'xyz3', 'xyz4']
print(split(x))
output :
['abc3', 'xyz4']
After entering any characters, the value which is stored in variable A is "0". Can anyone please assist me where I am going wrong as it is working fine if I enter number
Rookie
Public Sub MyFirstProgram()
Dim A As String
A = Val(InputBox("Enter your name", "NAME"))
MsgBox "My name is " & A
End Sub
The Val function converts a string to a Double numeric type.
Presumably, the names you are entering cannot be converted to a valid number, so the result is 0.
http://office.microsoft.com/en-us/excel-help/HV080557263.aspx
The Val function stops reading the string at the first character it can't recognize as part of a number.
So if you do something like =Val("123steve") it will return the numeric component: 123, but if you do =Val("Ebeneezer Scrooge") it stops, per the above remark -- since no characters have been converted to numeric value, it returns 0.
I get a string from a message /whisper
The string contains password:name:nameInHex
I want to find the first variable in the string and compare it with the password trigger and if the trigger == first variable in the string then continue to nr4 in the list.
I want to find the second variable in the string, name and convert it to hex.
I want to compare name with nameInHex and if it is true, then continue to invite the person to by using a chat command /invite
Split the string when you reach each colon, and store them their respective variables.
Then have your logic to process each once you have them stored in a variable
http://lua-users.org/wiki/SplitJoin
Start with
password,name,nameInHex=mystring:match("^(.-):(.-):(.-)$")
I'm writing some rows to a text file using groovy (grails 1.3.7) and I want to format the currency like this example output:
$100,000,000.00
$9,123,123.25
$10.20
$1,907.23
So basically right-justified, or left padded, with the dollar sign in front of the number so they all line up like the above. The first number is the longest we would expect to see. Right now I have an amount variable that is simply defined with a def and not string or number or anything specific like that but I can obviously change that if need be. Thanks!
You probably want to use NumberFormat.getCurrencyInstance(). This will return a NumberFormat object that uses the standard currency representation for your default Locale (or optionally, the one you pass in).
To right justify, you can use String.padLeft().
Example:
def formatter = java.text.NumberFormat.currencyInstance
def values = [0, 100000000, 9123123.25, 10.20, 1907.23]
def formatted = values.collect { formatter.format(it) }
def maxLen = formatted*.length().max()
println formatted.collect { it.padLeft(maxLen) }.join("\n")
//output
$0.00
$100,000,000.00
$9,123,123.25
$10.20
$1,907.23
In grails soemthing like this will format it nicely with comma separators.
<g:formatNumber number="${150000}" type="currency" currencyCode="USD"/>
For right aligning I would use style:
<td style='text-align:right;...'>