# Switch case using String value in UI-path

**URL:** <https://forum.uipath.com/t/switch-case-using-string-value-in-ui-path/173258>\
**Category:** Help\
**Tags:** string, question, system, activities\
**Created:** [December 2, 2019, 7:00am UTC](https://forum.uipath.com/t/switch-case-using-string-value-in-ui-path/173258 "2019-12-02T07:00:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raina\_Mani](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/raina_mani/32/61678_2.png) [@Raina\_Mani](https://forum.uipath.com/u/Raina_Mani)\
**Post date:** [December 2, 2019, 7:00am UTC](https://forum.uipath.com/t/switch-case-using-string-value-in-ui-path/173258/1 "2019-12-02T07:00:08Z")

</div>

Hello All,

I just want to explore 4 case in Switch. Saved as **ShortDesc** variable some text. If ShortDesc having doesn’t have any key word should choose case 1. If ShortDesc have “Strike 1” should choose case 2. If ShortDesc have Strike 2 should choose case 3. If ShortDesc have Strike 3 should choose case 4.

I need to operate Switch case as if shortdesc have keyword.

 ![SwitchCase](https://global.discourse-cdn.com/uipath/original/3X/2/2/22e00a98720695f1bb967ce2ee9d4f3ce4af1774.jpeg)

---

<div class="post-metadata">

**Author:** ![AshwinS2](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ashwins2/32/176686_2.png) [@AshwinS2](https://forum.uipath.com/u/AshwinS2)\
**Post date:** [December 2, 2019, 7:04am UTC](https://forum.uipath.com/t/switch-case-using-string-value-in-ui-path/173258/2 "2019-12-02T07:04:01Z")

</div>

Hi @Raina_Mani

Use Short Desc=String.empty in default

Case 2 ShortDesc=Strike 1

then do the manipulations like that for other cases

Thanks  
Ashwin S

---

<div class="post-metadata">

**Author:** ![kadiravan\_kalidoss](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/kadiravan_kalidoss/32/176690_2.png) [@kadiravan\_kalidoss](https://forum.uipath.com/u/kadiravan_kalidoss)\
**Post date:** [December 2, 2019, 7:32am UTC](https://forum.uipath.com/t/switch-case-using-string-value-in-ui-path/173258/3 "2019-12-02T07:32:54Z")

</div>

Hi @Raina_Mani,

I think we cant give expressions/variables in cases.

[switchCase.xaml](https://forum.uipath.com/uploads/short-url/6ciXK82ltqUBVixVCTsHFOoGb7N.xaml) (15.1 KB)

Try this defined for your scenario.

Thanks!

---

<div class="post-metadata">

**Author:** ![SowmyaLeo](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sowmyaleo/32/109068_2.png) [@SowmyaLeo](https://forum.uipath.com/u/SowmyaLeo)\
**Post date:** [December 2, 2019, 9:37am UTC](https://forum.uipath.com/t/switch-case-using-string-value-in-ui-path/173258/4 "2019-12-02T09:37:39Z")

</div>

@Raina_Mani:  
Kindly try the below steps:

1. Assign the Strike value eg:Strike 1, Strike 2,… to a variable. I think it is ShortDesk in your case.
2. Expression: ShortDesc TypeArgument: String
3. Case: Strike 1 (No double quotes here)  
 ![image](https://global.discourse-cdn.com/uipath/original/3X/7/8/784258ed19f22377d58e5777d41cb9b582f8f1d6.png)

Hope this helps.

---

<div class="post-metadata">

**Author:** ![cameronmcnz](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/cameronmcnz/32/170736_2.png) [@cameronmcnz](https://forum.uipath.com/u/cameronmcnz)\
**Post date:** [June 14, 2021, 10:24am UTC](https://forum.uipath.com/t/switch-case-using-string-value-in-ui-path/173258/5 "2021-06-14T10:24:30Z")

</div>

[![](https://global.discourse-cdn.com/uipath/original/4X/9/8/6/986699d2f37a4ddcb1aa6e1c34b51ce1226cbe3a.jpeg "How to Switch on a String in UiPath") ](https://www.youtube.com/watch?v=HswobQMeyHU)

You can most definitely use the [UiPath Switch activity](https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/example-uipath-switch-activity-conditional-explained-tutorial) with a String.

They key is to change the TypeArgument to [String in the switch](https://www.rpacertified.com/2021/06/13/uipath-string-switch-case-tutorial.html) activity’s properties window.

 ![](https://global.discourse-cdn.com/uipath/original/3X/6/1/618d113cd2af03f1d3ac563942ea75f7356b8b17.jpeg)

## UiPath Switch Expression Types

You’ll notice that the UiPath Swtich Activity works with int32, String, Object, array and in fact, any type you can browse to.

Just make sure all the types match up, both in the expression and the case. And in the case, leave out the quotes, otherwise the case will mess up. It’s one of the few cases in UiPath where a String is not double quoted.

 ![](https://global.discourse-cdn.com/uipath/original/3X/e/a/ea7e4278599a3ad76913c3138981ae8bcec7c4bd.jpeg)

[Get UiPath Certified](https://www.rpacertified.com/study-guide-uipath.html)

---

<div class="post-metadata">

**Author:** ![postwick](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/postwick/32/227083_2.png) [@postwick](https://forum.uipath.com/u/postwick)\
**Post date:** [June 14, 2021, 2:15pm UTC](https://forum.uipath.com/t/switch-case-using-string-value-in-ui-path/173258/6 "2021-06-14T14:15:29Z")

</div>

Unfortunately, there is no way to do what you want using a Switch, since you cannot put an expression into the Case. You’ll have to use multiple If activities.

They don’t have to be nested. I see people do this a lot and it’s unnecessary. Just do consecutive If activities…

If ShortDesc.ToUpper.Contains(“EXAMPLE 1”)

- do something

If ShortDesc.ToUpper.Contains(“EXAMPLE 2”)

- do something

If ShortDesc.ToUpper.Contains(“EXAMPLE 3”)

- do something

etc…

---

<div class="post-metadata">

**Author:** ![sandeep\_sonu](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sandeep_sonu/32/214048_2.png) [@sandeep\_sonu](https://forum.uipath.com/u/sandeep_sonu)\
**Post date:** [June 23, 2021, 2:00pm UTC](https://forum.uipath.com/t/switch-case-using-string-value-in-ui-path/173258/7 "2021-06-23T14:00:45Z")

</div>

@Raina_Mani  
We can do this using If condition within Switch case. Please find the below statement & snapshot and let me know if it is working for you  
if(string.IsNullOrEmpty(ShortDesc),“Case1”,If(ShortDesc.Contains(“Strike1”),“Case2”,If(ShortDesc.Contains(“Strike2”),“Case3”,“Default”)))

 ![image](https://global.discourse-cdn.com/uipath/original/3X/6/7/67d6edc222a6bceeb00a7f174e5d21dd90df112e.png)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [October 15, 2021, 3:02pm UTC](https://forum.uipath.com/t/switch-case-using-string-value-in-ui-path/173258/8 "2021-10-15T15:02:20Z")

</div>

Closed on October 15, 2021, 3:02pm UTC

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