Converting user input string to array/list

I’m having issues converting user input from string to arrays or a list.
I’m trying userinput.ToArray, but i’m encountering this error

Hi @pleasehelp

userinput= "A,B,C"
userArray=userinput.Split(","c)

userArray will be of Data Type Array(of String)

Could you please specify what are you storing in userinput variable so that I can help you with solution.

Regards,

@pleasehelp
Welcome to the forum

Unfortunately we cannot derive the details from your description and refer to the string.

Maybe the String is to split and has a dedicated delimiter char. So we would do

userArray = userinput.Split(";"c)

here ; was used for the splitting

feel free to learn a and explore by using the immediate panel:
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

grafik

Hello @pleasehelp, try this approach:

  1. Capture User Input:
  • Use the “Input Dialog” activity or any other method to capture user input as a string. Store this input in a variable, let’s call it userInputString.
  1. Convert to Array:
  • To convert the user input string to an array, you can use the Split method of the string in a “Assign” activity. For example, if the separator is a comma (,), create an “Assign” activity with the following expression:
userArray = userInputString.Split(","c)

In this expression, userArray is a variable of type String[], and we use ","c as the separator.
3. Convert to List (Optional):

  • If you want to work with a list instead of an array, you can convert the array to a list using the “Assign” activity. First, make sure you have a variable of type List(Of String) created, let’s call it userList. Then, use this expression:
userList = userArray.ToList()

This will convert the array userArray to a list userList.

Cheers! :slight_smile:

Hi @pleasehelp ,

Could you let us know what is the data value present in the userinput variable ? How would you want the userinput to convert to an Array ?

If you could provide us with a Sample Data and the converted Array format you need, then we would be able to help faster.

For a Quick Check, see if the below Expression helps and also the End Output is what you require :

{userinput}
1 Like

Apologies, the user input is a 4 digit number, that i’m comparing with another number to see if it matches.
if a number is the same number in the same position, i’ll print out a hint.
if a number is the same number in a different position, i’ll print out another hint.

@pleasehelp ,

We would need to understand what is meant by same number in a Different position.

Also, In that case, An Array would not be needed and you could perform the comparison directly using an If Activity with the below Condition :

YourInputNumVar.Trim.Equals(AnotherNumVar.Trim) 

Assuming both the variables are of type String.

e.g

number to be compared : 1139

user guess : 1391

the first ‘1’ is the same number in the same position
the second ‘1’ is the same number in a different position. i.e there’s a ‘1’ in the hundred’s place, but user’s guess is in the ones place

we could create a string array as by:
grafik

But in general we feel that you are looking more at a compare / report task