The Split function in UiPath is a string manipulation method that divides a text string into an array of substrings based on a specified delimiter (like a comma, space, or newline). It is essential for parsing data from CSV files, log files, user inputs, or any structured text. You can use it in any activity that accepts expressions, such as Assign, Write Line, or Message Box. Before you start, you should have a basic understanding of UiPath Studio and have a project open where you can add activities.
What You’ll Need
- UiPath Studio (Community or Enterprise) installed and a project open.
- Basic familiarity with the UiPath interface, especially the Activities panel and the Designer panel.
- A string variable or a literal string you want to split (e.g., “apple,banana,cherry”).
Step-by-Step
- Create a String Variable – In the Variables panel (usually at the bottom), click “Create Variable.” Name it
inputStringand set its type toString. In the Default value field, type a sample string like"apple,banana,cherry"(without the outer quotes in the value field). This variable will hold the text you want to split. - Create an Array Variable – Create another variable named
resultArrayand set its type toString[](array of strings). This will store the split parts. You can leave the Default value empty. - Add an Assign Activity – Drag an Assign activity from the Activities panel onto the Designer panel. This activity lets you assign a value to a variable.
- Configure the Assign Activity – In the Assign activity’s properties, set the To field to
resultArray. In the From field, enter the expression:inputString.Split(","c). Note thecafter the comma – it tells UiPath to treat the comma as a character (Char) rather than a string. Click outside the field to validate; you should see no errors. - Run the Workflow – Press F5 or click Run to execute. The Assign activity will split the string at each comma and store the resulting substrings in
resultArray. - View the Result – To verify the split, add a Message Box activity after the Assign. In its Text property, enter:
String.Join(", ", resultArray). This joins the array back into a readable string. Run again – you should see “apple, banana, cherry” in the message box. - Use Other Delimiters – To split by a space, use
inputString.Split(" "c). For a tab, usevbTab(e.g.,inputString.Split(vbTab)). For a newline, useEnvironment.NewLineorvbCrLfas the delimiter:inputString.Split(Environment.NewLine.ToCharArray())– note that newline is two characters, so you need to pass a char array. - Split by Multiple Delimiters – If you need to split by any of several characters (e.g., comma or semicolon), pass a char array:
inputString.Split(New Char() {","c, ";"c}). - Remove Empty Entries – To skip empty substrings (e.g., from consecutive delimiters), use the overload:
inputString.Split(New Char() {","c}, StringSplitOptions.RemoveEmptyEntries). - Split a String from a File or Input – You can read a file with
File.ReadAllTextor get user input withInputDialog, then assign that toinputStringbefore splitting. For example, drag a Read Text File activity, set its FilePath to a CSV file, and store the result ininputString.
Common Mistakes
- Forgetting the
csuffix – If you writeinputString.Split(","), UiPath throws an error becauseSplitexpects a Char or Char array, not a String. Always addcafter a literal character. - Using the wrong variable type – The result of Split is an array of strings. If you try to assign it to a String variable, you’ll get a type mismatch error.
- Splitting by newline incorrectly – Using
Split(vbCrLf)as a single character fails because it’s two characters. UseSplit(New String() {vbCrLf}, StringSplitOptions.None)or convert to a char array. - Ignoring empty entries – When your data has consecutive delimiters (e.g., “a,,b”), the default Split includes empty strings. If you don’t want them, use
StringSplitOptions.RemoveEmptyEntries. - Not handling case sensitivity – Split is case-sensitive. If you need case-insensitive splitting, you’ll need to use a different approach, like Regex.Split.
Tips
- Use
StringSplitOptions.Noneexplicitly – When using the overload with options, always specifyStringSplitOptions.NoneorRemoveEmptyEntriesto avoid confusion. - Test with a simple string first – Before applying to complex data, test your Split expression with a hardcoded string to ensure it works as expected.
- Combine with LINQ for advanced processing – You can use
resultArray.Where(Function(s) s.Length > 2).ToArray()to filter out short substrings. - Use
String.Splitfor CSV parsing – For simple CSV lines, splitting by comma works, but be aware of quoted fields containing commas – for that, consider using a CSV parsing package or a Regex pattern. - Remember that Split returns a new array – The original string remains unchanged. If you need to modify the original, assign the result back to a string variable after joining.
Troubleshooting
- Error: “Overload resolution failed because no accessible ‘Split’ can be called with these arguments” – This usually means you passed a String instead of a Char. Ensure you add
cafter the delimiter literal, or useNew Char() {...}for multiple delimiters. - Result array is empty or not what expected – Check the delimiter. If your string uses spaces but you split by comma, you’ll get one element. Use the Immediate Panel (Debug > Windows > Immediate) to inspect
inputStringandresultArrayduring debugging. - Split by newline yields extra empty lines – This happens because newline is often
\r\n(two characters). UseSplit(New String() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)to clean it up. - Cannot assign to array variable – If you get a type mismatch, confirm that the variable type is
String[]and notStringorObject. - Split works in a test but not in a loop – If you’re splitting inside a For Each, remember that each iteration may have a different string. Ensure you’re reassigning the array each time, not accumulating.
Frequently Asked Questions
- Can I split a string by a word (like “and”)? – Yes, but Split expects a Char or Char array. To split by a multi-character string, use
inputString.Split(New String() {"and"}, StringSplitOptions.None). - How do I split a string into individual characters? – Use
inputString.ToCharArray()to get a Char array, or convert to string array:inputString.Select(Function(c) c.ToString()).ToArray(). - Is Split case-sensitive? – Yes, by default. If you need case-insensitive splitting, use
Regex.SplitwithRegexOptions.IgnoreCase, e.g.,Regex.Split(inputString, ",", RegexOptions.IgnoreCase). - Can I split a string from a CSV file directly? – Yes, read the file content into a string variable, then use Split. But for complex CSV with quoted commas, consider using a dedicated CSV parser like
Microsoft.VisualBasic.FileIO.TextFieldParser. - What is the difference between Split and Substring? – Split divides a string into multiple parts based on a delimiter, returning an array. Substring extracts a single contiguous portion based on a start index and length.
- How do I split a string by multiple different delimiters at once? – Pass a Char array to Split:
inputString.Split(New Char() {","c, ";"c, "|"c}). This splits at any of those characters.
Related
- Data Entry Jobs From Home for Students: Real Guide
- Google Sheets Remove Dropdown From Column
- Random Number 1-3: How to Generate One
Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.
More in Formulas & functions
- Excel Formula with Multiple Criteria: SUMIFS, COUNTIFS, AVERAGEIFSThe best formula to use when you need to sum, count, or average data based on multiple criteria…
- Excel FILTER Function: Filter Rows by Partial TextTo return rows where a column contains part of a word or phrase, combine Excel’s FILTER function with…
- Arcade Number to String? Excel Formula & FixesThe direct answer: there is no built-in Excel function called “ARCADE” for converting numbers to text. If you…
- Calendar Date Formula in Excel: ExamplesThe most useful Excel calendar date formula is =DATE(year,month,day), which combines a year, month, and day into a…
- COUNTIF Excel Contains Part of Text: Examples & TipsYes. In Excel, use COUNTIF with asterisks around the text you want to find: =COUNTIF(A2:A8,"*North*") counts cells in…
- Gtt per Min Formula: Examples and Safe CalculationThe gtt per min formula is gtt/min = (mL × drop factor in gtt/mL) ÷ time in minutes.…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.