Remove Blank from the string

Hi All,

I am getting a string result from custominput activity as strResult of type String
“112”,“11”,“12”,“Blank”,“Blank”,“Blank”

I have used foreach loop of string type as as exractCustomresult and stored all these values into different variable.
But I want the BOT before assigning thses to diff variables like var1=“112”, var2=“11” etc. It should remove all the “Blank” and extract only values containing digits or data and then assign these to different variable.
Please support

You can use a if condition inside the for each loop to skip the value “Blank”

as if item.tostring <> “Blank”, in THEN condition, do the necessary @somya177

but the requirement is to remove these “Blank” and keep the string to be" “112”,“11”,“12” " that’s it

Try this in assign as

yourArray = yourArray .Where(Function(s) s <> “Blank”).ToArray @somya177

2 Likes

what is s?

S is a parameter for the function which is a temporary variable created while running that particular function. You can replace it with any @somya177

it is showing error that that cannot do implicit conversion from system.string to ienumerable.collections

Below is the output I am getting from customForm result
I want that every time if there are blank then they should be truncated from the output

“radioYes”,“112”,“1”,“2”,“blank”,“blank”,“blank”

the output should be left is : “radioYes”,“112”,“1”,“2”
and then these should be assigned to different var like var1= radioyes
var2= 112
var3=1… etc

How are you trying to do that @somya177? I provided the solution if you have a string array.use assign activity and then use the above . Then you can directly give the string array in for each activity

my only requirement is to remove these “blank” from this string…

This will help you, you are deleting the values from the array and using for each to iterate the array @somya177

image

Hi,

Please find my XAML.
I created using the logic u provided but still I get “blank” in the writeline.
I want only the values and remove "blank"FormTest.xaml (10.1 KB) HTMLPage1 -.html (5.7 KB)

Remove the blanks first and then split them with “,” @somya177

you are doing it vice versa now :slight_smile:

result from customInput form is of type string. It cannot be array of strings so its not possible to apply where function in it

@somya177
Please Check in your provided XAML the Cases of “Blank”. In the Where statement is blank written the b in lower case. In your Post above the B is written in uppercase.

Kindly note. splitting a String Variable returns a String Array. So the provided code should do this as expected.

Hy @somya177

You can use regex expression for removing the blanks,
System.Text.RegularExpression.Regex.Replace(strResult,“Blank”,"")

And then you can use Split Activity and store them into Array of String, Then you can access each item like
strArr(0), strArr(1), strArr(2)

Thanks.
Goutham Vijay

i got this error:

19.7.0+Branch.master.Sha.8c253d13718eed5c7db27daef6facd1fe1b0d067

Source: For Each

Message: Unable to cast object of type ‘System.Char’ to type ‘System.String’.

Exception Type: System.InvalidCastException

RemoteException wrapping System.InvalidCastException: Unable to cast object of type ‘System.Char’ to type ‘System.String’.
at UiPath.Core.Activities.ForEach1.InternalExecute(NativeActivityContext context, IEnumerator valueEnumerator) at UiPath.Core.Activities.ForEach1.Execute(NativeActivityContext context)
at System.Activities.NativeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Could you please place your latest XAML here, so we can help you and will get it done.

I found the solution and I got results but then I got struck I another thing.:

This is how I am getting the result after assigning Capture logic to the variables;

Now the thing is I need to pass these amount values to the webapplication.
So the BOT has to click on “Continue” button till it doesn’t find empty string i.e splitamount2 in this case and when it gets this empty value it has to click on payment button.

I have used foreach loop to do so i.e. foreach item in extractCustomResult where extractCustomResult is stringtype array and inside foreach I am passing a if condition item.ToString.Equals(String.IsNullOrWhiteSpace)=false then BOt will click on Continue
else click on payment button.
BOT worked fine for first iteration and after second iteration it was supposed to click on Payment but it moved to then part and click on Continue…i.e. it read previous value 11 which is wrong.
can u please support in this

Can You Try String. IsNullOrEmpty function instead of String.IsNullOrWhiteSpace
and change the condition in this way:
String.IsNullOrEmpty(item.ToString)
then: click payment
else: click continue