siddhi
(Siddhi)
1
Hi Community,
I’ve a string like this:
“C:\Users\srani\Downloads\R5542565C_MG000003_2279260_PDF.pdf”
I need to extract the number which I mentioned in bold (i.e. 2279260) and this number is dynamic which changes in every run.
PLease suggest .
Thanks.
@siddhi
Try with regex
With Assign Activity
MatchValue=System.Text.RegularExpressions.Regex.Match("C:\Users\srani\Downloads\R5542565C_MG000003_2279260_PDF.pdf", "(?<=_)\d+(?=_)").Value
With Match Activity:
- Drag and drop a Matches activity onto your workflow.
- In the Properties panel, provide the following values:
- Input:
"C:\Users\srani\Downloads\R5542565C_MG000003_2279260_PDF.pdf"
- Pattern:
(?<=_)\d+(?=_)
- Result: Create a variable of type
System.Collections.Generic.List<UiPath.Match>
to store the extracted matches (e.g., named resultList
).
- Add a For Each activity below the Matches activity.
- Set the TypeArgument of the For Each activity to
UiPath.Match
.
- Set the Values property of the For Each activity to
resultList
.
- Inside the For Each activity, you can access each match using the CurrentItem variable.
- To extract the desired number, add an Assign activity inside the For Each loop.
- Left side: Create a variable to store the extracted number (e.g., named
extractedNumber
).
- Right side: Assign the value
CurrentItem.Value
to extractedNumber
.
vrdabberu
(Varunraj Dabberu)
4
Hi @siddhi
use the below syntax
Assign the path to a variable and use the split to that variable.
variable.split("_"c)(2)
1 Like
Parvathy
(PS Parvathy)
6
HI @siddhi
Try using below expression:
input: “C:\Users\srani\Downloads\R5542565C_MG000003_**2279260** _PDF.pdf”
input.Split("_".ToCharArray).Reverse()(1)
Hope it helps!!
Regards,
Veera_Raj
(Veeraraj Sethuraman)
7
first use
str_var= path.getfilenamewithoutextension( “C:\Users\srani\Downloads\R5542565C_MG000003_2279260 _PDF.pdf”)
str_var = str_var.split("_"c)(2).tostring
try this
1 Like
siddhi
(Siddhi)
8
Thanks everybody for the response.
system
(system)
Closed
9
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.