How to Switch on a String in UiPath |Video upload date:  · Duration: PT4M53S  · Language: EN

Learn how to use the Switch activity to branch on string values in UiPath Studio with quick steps and clear examples for reliable RPA flows

So you need to branch your automation based on exact text and you do not want to end up in a nest of If activities that looks like a plate of developer spaghetti. The Switch activity in UiPath Studio is the tidy answer. This guide shows how to configure Switch for String values, avoid common traps, and test like a responsible automation adult.

Why use Switch for string branching

SwitchActivity makes branching on exact string values clear and fast. When your logic depends on specific text such as status codes and user choices, Switch reduces visual noise and debugging time compared to a chain of If activities. It also helps when you have many cases and need a readable structure.

Quick setup steps for the Switch activity

  1. Create a workflow and declare a string variable. A predictable name like myString saves future confusion when you are debugging at 2 a m.
  2. Drag the Switch activity into your sequence or flowchart. Use Switch when you need exact string matches rather than boolean checks.
  3. Set TypeArgument to String from the dropdown. This forces the activity to expect string values and avoids type mismatch drama.
  4. In the Expression field type your variable name, for example myString. Add cases by clicking Add Case and enter the exact string for each branch. Exact matching matters, so watch casing and whitespace.
  5. Add a Default case to handle unexpected values. Put a Log Message or Write Line there so you can blame something other than yourself later.

Example normalization step

Strings lie. They come with random spaces and weird capitalization. Standardize them before the Switch activity with an Assign activity. For example set myString to myString.Trim().ToLower() so your case values can be simple and predictable.

How to add cases and what to watch for

Add each case with the exact string you want to match. UiPath uses exact matching for Switch when the TypeArgument is String. That means "Pending" does not equal "pending" and " ok" is not "ok". If you want case insensitive matching use normalization as described above.

  • Case values must be exact strings
  • Whitespace differences cause mismatches
  • Use the Default case for unexpected input

Testing and debugging your Switch branches

Run the workflow and change myString to exercise every branch. Add Write Line or Log Message activities inside each case to confirm the right path executed. If something goes wrong the Default branch should log the unexpected value so you can investigate the source data without screaming into the void.

Best practices and small survival tips

  • Trim and normalize input early with myString = myString.Trim().ToLower() to avoid casing and whitespace bugs
  • Keep case values as constants when possible to reduce typos
  • Use descriptive names for cases so the workflow reads like a manual for future you
  • Log unexpected values in the Default case so you have a breadcrumb trail

The Switch activity is simple, robust, and keeps your UiPath Studio projects from turning into a horror show. Configure TypeArgument to String, normalize the data, add clear cases and a Default branch, then test. That is all it takes to go from chaos to slightly smug automation success.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.