Trim the string

Hello all.
I’ve a full path “C:\Users*****\Documents\SAP\SAP GUI\RC2AnalysisDataID820220511.zip”.
How to trim 20220511.zip from the above path?

Hi @happyfeat87,

If you wanted the full file name from the full path, you could do the following:

StringVar = FilePath.ToString.Split({"\"},StringSplitOptions.None).Last.Trim
Edit: This above expression gives the output “RC2AnalysisDataID820220511.zip”, should you need to use the filename for anything.

From there, you could use Regex pattern \d{8}\.\w* to get the part you need:
image

I take it the last 8 characters are a date format, so I have used {8} for matching the digits

1 Like

Hi,

Can you try the following expression?

System.Text.RegularExpressions.Regex.Match(yourString,"\d{8}\..+$").Value

Regards,

2 Likes

@william.coulson yes. In C:\Users*****\Documents\SAP\SAP GUI\RC2AnalysisDataID820220511.zip”.

20220511 is dynamic( In date format).

Hi @happyfeat87,

In this case, either mine or @Yoichi’s regex patterns will work for you, trusting the date format will always remain in the same format of 8 numbers.

Edit: @Yoichi’s regex pattern will work better as it will still pick up the item if there is something after “.zip”

1 Like

How to get the string C:\Users*****\Documents\SAP\SAP GUI\RC2AnalysisDataID8 ignoring 20220511.zip.
Currently I am trying this “C:\Users\Dinesh\Documents\SAP\SAP GUI\RC2AnalysisDataID8”&Datetime.now.tostring(“yyyyMMdd”)&“.zip”

Hi @happyfeat87,

Try using Regex to get that item out, and then replace it with nothing:

In an assign:
RegexItem =

In a seperate assign:
Filepath = Filepath.Replace(RegexItem,"")

If RegexItem is “20220511.zip”, then replacing it with nothing should give you the expected filepath.

Edit: Though, if you already have the filepath, you won’t need to manipulate it? You’re already referring to it:

Just assign everything before the first & to a variable.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.