String manipulation: split and .length function

Dates.xaml (5.8 KB)

Hi all,

I’m trying to get the last 8 characters out of a string, but I did not manage…
Can you please have a look what I’m doing wrong.
I’m first splitting the string at the “.” and then I want the last 8 characters of the index(0).

So from “XXXXXXXXXXXXXXXX_20180826.zip” i want to retrieve 20180826 (and if possible transform it to date format). Unfortunately I get the following error: Assign: Object reference not set to an instance of an object.

Thanks!

In your case XXXXXXXXXXXXXXXX_20180826.zip

Dont split, it makes you create an array and then use indexing to get it
Try:
string.Substring(string.IndexOf(“_”)+1,8) which will give you 20180826

1 Like

Hi @nadim.warsi

I cannot work with the "_ "actually, because in reality XXXXXXXX can contain ABC_DEF_ or ABDEF_GH.

1 Like

Then just a small function change:

string.Substring(string.LastIndexOf("_")+1,8) which will give you 20180826

1 Like

And if you want to change the type of it to date use the below:

Date.ParseExact(output, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture)

Note: output format is 20180826 that is why yyyyMMdd, if any other value for it then this will error so keep a tap on that

Details on the function:

1 Like

As always you can also use Regex to extract the date from your filename if you are familiar with it!. See the attached workflow.

Sequence.xaml (6.7 KB)

Thanks @nadim.warsi

Looks like a good solution but I get an error (see output)
What should I do?

right side should be variable test :slight_smile:

Oh of course… How silly… Should have known!! :blush:

1 Like

Sorry, but question here as well.
What should I be replacing in your code? “date” and “output”?
Also, which variabletype should I assign?

just replace dateformat with testEnddate rest is good.

And dateformat type is correct System.DateTime

2 Likes

Thanks, works fine

1 Like