Hey All,
I am using a txt file with 5 lakh records where in i need to extract desired string from each row.
have stored text file in Match Collection and using for each row to iterate as below :
Input Eg : 1168~abcd~null~3~1~0~2009-10-27 05:00:00~2009-10-27 05:00:00~2021-06-16 10:13:35~2009-10-27 05:00:00~2009-10-28 01:13:34~
Desired Output : Need to extract 1st value before ~ and storing in str_SerialNo variable=1168
Anil_G
(Anil Gorthi)
September 25, 2023, 5:43am
2
@prerna.gupta
are you facing any issue with it?
Can you please elaborate the issue
You can use item.Value.Split("~"c).First
Assuming matchcollection is a collection of match and not strings
Can you please let us know what is there is match collection if this does not work
Cheers
mkankatala
(Mahesh Kankatala)
September 25, 2023, 5:44am
3
Hi @prerna.gupta
You can use the below regular expressions.
System.Text.RegularExpressions.Regex.Matches(yourstringinput.ToString,“(^\d+(?=~))”)
Hope it helps!!
The expression u r using is already correct
May I know what issue u r facing
@prerna.gupta
This is similar to item.ToString.Split("~"c)(0) and it extract only 1st numeric digit before ~ ie 8 instead of 1168
For each - list of match collection only
HI @prerna.gupta
str_SerialNo=strinput.Split({“~”},StringSplitOptions.RemoveEmptyEntries)(0)
strinput = “1168~abcd~null~3~1~0~2009-10-27 05:00:00~2009-10-27 05:00:00~2021-06-16 10:13:35~2009-10-27 05:00:00~2009-10-28 01:13:34~”
you can try this
item is of match collection type.
Suggested is throwing error MatchCollection cannot be converted to String
mkankatala
(Mahesh Kankatala)
September 25, 2023, 5:54am
9
Okay @prerna.gupta Use the below one
System.Text.RegularExpressions.Regex.Match(yourstringinput.ToString,“(^\d+(?=~))”).Value
Hope you understand!!
you can change the variable type to matchcollection
then it will work
@prerna.gupta
Anil_G
(Anil Gorthi)
September 25, 2023, 5:56am
11
@prerna.gupta
Can you please use a log message and show what is there is each item…please log the item…looks like the matchcollection itslef is missing 116 in it
Cheers
I need to extract multiple values from Input String due to which not using RemoveEmptyEntreis function
To be precise i need to extract 2 values
Value 1 = Anything before 1st ~ symbol = 1168
Value 2 = Anything after 1st ~ symbol = abcd (this is working good using item.ToString.Split("~"c)(1))
Issue Facing - Getting only 1st numeric digit before ~
Output = 8
Desired Output = 1168
HI @prerna.gupta
1.Value 1 = Anything before 1st ~ symbol = 1168
System.Text.RegularExpressions.Regex.Split(strinput,“~”)(0)
2.Value 2 = Anything after 1st ~ symbol = abcd
System.Text.RegularExpressions.Regex.Split(strinput,“~”)(1)
let me know its working or not for you
I’m sharing the xaml you can follow same as it is
Xaml : - RegEx for Text File.zip (1.9 KB)
@prerna.gupta
if not you can try this screenshots
you can see the out
@prerna.gupta
can you share the screenshots of your flow
@prerna.gupta