Delete certain parts of a String

Hi everyone,

There is a way to eliminate certain parts of a string. example
FECHA DE GENERACIÓN: 26/04/2019 HORA: 4:00 P.M.
I want to erase: GENERATION DATE: _____ TIME: 4:00 P.M.(this time varies)
I just want to stay with the text 04/26/2019, but this text also variate

Thanks in advanced

1 Like

You can use regex replace to replace everything that isn’t in the date format with an empty string. s the date format in dd/MM/yyyy or MM/dd/yyyy format?

EDIT: Since you’re just pulling out the date only, I wouldn’t even use regex replace. I would just pull out a regex match instead. Put this in an assign activity where YourDate is a string variable, and InputText is a string variable. YourDate = system.Text.RegularExpressions.Regex.Match(InputText,"\d{2}/\d{2}/\d{4}").ToString

2 Likes

Hi @askPWC

StrText.ToString.Substring(20,12)

Thanks
Ashwin S

dd/MM/yy, i just want want that part

Sorry that im new,
What does this code?

@askpwc - I edited my answer while you were replying to me. Check the edit

This is a string variable like based on that we need to do string manipulations

Thanks
Ashwin S

Hi buddy @
This can be done with this assign activity like
in_text = “FECHA DE GENERACIÓN: 26/04/2019 HORA: 4:00 P.M”
out_date_value =Split(in_text.Split(“GENERACIÓN:”)(1).ToString.Trim,“HORA” )(0).ToString.Trim
see
image
this would work for sure
Cheers @askPWC

@AshwinS2 and @Palaniyappan - both of these answers would work in this exact situation but are quite fragile. Substring is ok if it’s in the exact spot every single time. String split works if it will always be preceded by those exact words and spaces, and is always in the same order. Regex will work in all cases

Fine what if date format changes

@Palaniyappan - that is the risk for the regex solution. If the pattern of what you’re looking at changes, then you’d need to find a new pattern. As long as it is ## / ## / #### (without spaces in between, where # = any digit) then it would not fail. If the entire pattern is apt to changes, then I agree a different method should be used. In general it is more likely that the order of words would change rather than the actual format of the date though

Yah thats why suggested split buddy
it can take these format
dd/MM/yyyy
or
MM/dd/yyyy
or
yyyy/MM/dd
or
yyyy/dd/MM
or
even this
yyyy MMMM dd

Cheers @askPWC

I still think this is more prone to error based on the information provided. If there were multiple date formats to be pulled out, it’s better to include that in your regex pattern. It’s always a case-by-case situation though and is dictated by the process itself

@Dave
Thanks for the Support

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