SPLIT - Find value after specific string

Hello, I am trying to split a really long string and use the numerical value after a specific string. I tried using index but the values can change so it may not always be in the same place. I will post a portion of the String Array below (There are tons more of things before and after the portion that I am posting. I need the number value -300.00 that comes after the string “Penalty”. Thank you in advance.

“\WriteOff":{"fieldValue":"00","Penalty":{"fieldValue":"-300.00"},"StartDate":{"fieldValue":"000000"}”

Is this from a JSON? If you deserailize it you can do

(string)JObject.Parse(longString).SelectToken(“$..Penalty.fieldValue”)

If it’s just a string, then you’d have to use regex. Although kinda tough to determine what would work for any example.

Maybe try
Regex.Match(stringInput, “Penalty.*?“fieldValue”:”(-?\d+.\d+)", RegexOptions.IgnoreCase).Groups[1].Value

It is a String. I tried the regex you suggested but did not work.

Hi @Lance_Daigle,

Since the position can change, index won’t be reliable here.
You can just grab the number that comes after “Penalty” using Regex.

System.Text.RegularExpressions.Regex.Match(yourString, “Penalty”“:{”“fieldValue”“:”“(-?\d+.?\d*)”“”).Groups(1).Value

That will return -300.00.

It looks for the word Penalty and captures the numeric value inside fieldValue, so it doesn’t matter where it appears in the string.
If the string is always proper JSON, even better option is to deserialize it and directly read:

jsonObj(“Penalty”)(“fieldValue”).ToString

1 Like

That looks like JSON. You should parse it as JSON to properly retrieve whichever values you want. Those are name/value pairs.

This looks like a json .
Use deserislise activity and store output in jsonObj
Then use assign as below :
penaltyValue = jsonObj(“Penalty”)(“fieldValue”).ToString

Tried the JsonObj route and I am getting this error. Option Strict On disallows implicit conversions from ‘String’ to ‘Integer’.

Show us your Deserialize JSON activity and the full JSON from the file or wherever you’re getting it.