# Split string for "2d 5h 30m"

I have a problem. The user input is something like "2d 5h 30m", which means 2 days 5 hours and 30 minutes. What I want to do is to make this format datetime into how many minutes. So I need to split the string which user input and do the calculation. For String_Split function, I don't know how to deal with the output. Can you show me an example how to do that?

Thanks.

Hi Nina,

When you do a String_Split on the space (" "), you get three rows, 2d, 5h and 30m.

Then you have to do a foreach, because you can't orchestrate the user input and you must validate the user input.

• Check the last digit
• is it a "d"?
• Strip the last digit, convert to integer and multiply with (24*60)
• is it an "h"?
• Strip the last digit, covert to integer and multiply with 60
• is it an "m"
• Strip the last digit, convert to integer.
• sum up all outputs and you have your time in minutes.

Kind regards,

Remco Dekkinga

Remco Dekkinga wrote:

Hi Nina,

When you do a String_Split on the space (" "), you get three rows, 2d, 5h and 30m.

Then you have to do a foreach, because you can't orchestrate the user input and you must validate the user input.

• Check the last digit
• is it a "d"?
• Strip the last digit, convert to integer and multiply with (24*60)
• is it an "h"?
• Strip the last digit, covert to integer and multiply with 60
• is it an "m"
• Strip the last digit, convert to integer.
• sum up all outputs and you have your time in minutes.

Kind regards,

Remco Dekkinga

Thank you for your help! I saw the output of String_Split is a Text Record List but I don't know how to get the output value when I use this function. Can you provide me an example?

There are two options and in your case I would go for option 1:

1. Foreach and walk through the list

= String_Split.List.Current.Text.Value

2. If you know which part you need, go there directly using the zero-based index.

= String_Split.List[0].Text.Value for the first element

= String_Split.List[2].Text.Value for the third element

The second option will throw an error if you give an index which is out-of-range.

Hope this helps!

Kind regards,

Remco Dekkinga

Remco Dekkinga wrote:

There are two options and in your case I would go for option 1:

1. Foreach and walk through the list

= String_Split.List.Current.Text.Value

2. If you know which part you need, go there directly using the zero-based index.

= String_Split.List[0].Text.Value for the first element

= String_Split.List[2].Text.Value for the third element

The second option will throw an error if you give an index which is out-of-range.

Hope this helps!

Kind regards,

Remco Dekkinga

Hi,

In my situation, I have a estimatedtime field in the detail page.

What I want to do is to split this EstimatedTime on this page and make it as minutes. So do I need to call String_Split function in the page preparation? Or do I need to create a local variable? Seems I can't use this function the data type is Text Record List.

You say For each and go through list, I don't know what record list should be put in the for each.

Is that correct?

Thank you very much.

Solution

Hi Nina,

This is how it should work.

Hope this clears up the questions you still have.

Kind regards,

Remco Dekkinga

Solution