How to fetch only a particular part of a string in uipath

HI i am new to uipath. Could you please suggest me how to retrieve a part of string eliminating spaces.

For example : E54432 A

in output i need only E54432 and not A.(ie.need to fetch characters before spaces.)

Can any one suggest the logic for the same?

Hello @Asha_chandran! For that string, there’s a simple solution using string splitting by spaces. Please take a look over here: How to Split a String - #8 by vikas_reddy_Vicky
If that doesn’t solve your problem, let us know!

You can Split the string by spaces. String.Split(" “c) returns an array of the former string split by spaces. String.Split(” "c)(0) will return “E54432”.

Thank you … i wil try with this

1 Like

Will i able to eliminate underscore(_), dash - using the same logic?

How can i include all these in single logic?

@Asha_chandran

Is underscore and dash are in between text or in place of space ?

For Example : A1307P_KO1

@Asha_chandran

In this case, First we have to check String contains underscore or dash etcc…

If Input.Tostring.Contains(““)
Then Input.Split(”
“c)(0)
Else Input.Tostring.Contains(”-”)
Then Input.Split("-"c)(0)

install the work manager activity
and then use split string activity
in output panel you have separators that you put in according to you

Is it possible to use 3 special characters dash,underscore and spaces in split function ?

when i tried to implement if else statement it throws me compiler error.

“End of the statement expected”

HI ,

Capture

i have a input value"423435345 D45657H 900000000000" when applied the below condition it is not fetching the value D45657H

APA_Descr.Split(” "c)(1)

Can anyone help me to sort out the issue?

HI Lakshman

i tried the same code that you suggested.

But when there is multiple white spaces the condition fails. Any suggestion?

@Asha_chandran

Try this:

APA_Descr = “423435345 D45657H 900000000000”

                   APA_Descr.Split(" ".ToCharArray)(1).Trim

Still the same problem… if there are 2 spaces then it doesn’t accept.

hello @Asha_chandran
Try increasing the index number if there are two spaces it is considering the first space as its value so if you put this code
Yourvariable.Split(CChar(" "))(2) it’ll get your value if there are two spaces

1 Like

@Asha_chandran, Use this regex pattern to remove unwanted spaces between words -

\s+

Cheers!!

Thanks lakshman. This worked.

1 Like

@Asha_chandran

Could you please close this thread by marking my above post as solution. (The one I provided the correct solution)

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