I’ve tried this and not getting what I expect.
So i’m reading a CSV and the variable name is CSVFundSelection1 and in that cell it has Emerging Markets (100). And what i’m wanting to do is remove everything but the 100.
This is what i put in the Assign:
System.Text.RegularExpressions.Regex.Replace(CSVFundSelection1.ToString,“[^0-9]”,“”)
So now i have a new issue so the CSVFundSelection1 now has Emerging 2020 Markets (1188). So when i use the above expression i get 20201188. and all i need is 1188.
I have tried this and it doesn’t work:
CSVFundSelection1.Trim.ToString.Replace(“(”,“” ).Replace(“)”, “”)
I’ve been able to remove the ( ) but all the text stays.
Thanks!
I would still suggest you use a Regex pattern. You can find out how to do the pattern with many examples and tutorials online.
Using the Split option works though, but I would normally do it like this:
CSVFundSelection1.Split("("c)(1).Split(")"c)(0)
So it takes the string after “(” and before “)”
The Regex solution would be like this:
System.Text.RegularExpression.Regex.Match(CSVFundSelection1, "(?<=\()(.*)(?=\))").Value
or
System.Text.RegularExpression.Regex.Match(CSVFundSelection1, "(?<=\()([0-9]{1,10})(?=\))").Value
So it simply pulls the string that is between ( ) or second one is pull it if only it’s digits 0-9
Also, get in the habit of storing this pattern in a variable or part of a config dictionary.
I’ll also add that if you use the Split method, make sure you verify it contains a Parenthesis or it will throw an error. You can do this with an If activity or using If() inside the code, like my below example…
If(CSVFundSelection1.Contains("(") and CSVFundSelection1.Contains(")"), CSVFundSelection1.Split("("c)(1).Split(")"c)(0), "")
OK. I have another csv question. So my cell has two values in it and the first part can vary but i know the end of the cell the last 11 digits i need to pull in one variable and the first part i can do a trim to end to get the empty spaces.
Here is what the cell looks like: