How to swap two string variables without using the third variable

How to swap two string variables without using the third variable

Use Case Description

How to swap two string variables without using the third variable
str var1 = first
str var2 = second
i need to swap theese two variables without using the third variable
ouput

var 1 = second
var 2 = first

AS-IS WORKFLOW, TO-BE WORKFLOW

-

Other information about the use case

Industry categories for this use case: Public Sector

Skill level required: Beginners

UiPath Products that were used: UiPath Studio, UiPath Orchestrator

Other applications that were used: -

Other resources: How to swap two string variables without using the third variable
str var1 = first
str var2 = second
i need to swap theese two variables without using the third variable
ouput

var 1 = second
var 2 = first

What is the top ROI driver for this use case?: Accelerate growth and operational efficiency

HI Developer

var1 = "second"
var2 = "first"

var1 = var1 & var2
var2 = var1.Substring(0, var1.Length - var2.Length)
var1 = var1.Substring(var2.Length)

Thanks
Hope it will helps you

Output:

Hi @venkatasai

FOR STRING

strvar1=“second”
strvar2=“first”

strvar1 = strvar1 + strvar2
strvar2 = strvar1.Substring(0, strvar1.Length - strvar2.Length)
strvar1 = strvar1.Substring(strvar2.Length)

OR

strvar1 = strvar2 + “~” + strvar1
strvar2 = strvar1.Split("~“c)(1)
strvar1 = strvar1.Split(”~"c)(0)

FOR INT

strvar1 = strvar1 XOR strvar2
strvar2 = strvar1 XOR strvar2
strvar1 = strvar1 XOR strvar2

Hope it will helps you :slight_smile:
Cheers!!

Hi @venkatasai

strVar1= "first"
strVar2= "second"
strVar1= strVar1+strVar2
strVar2= strVar1.Substring(0, strVar1.Length - strVar2.Length)
strVar1= strVar1.Substring(strVar2.Length)
Message Box-> strVar1
Message Box-> strVar2



Hope it helps!!
Regards

Hi @venkatasai

You can use Multiple Assign activity . I have tried to replicate it from my end using these steps :slight_smile:
1 . str1 = “abc” , str2= “def”
2 . str1 = str1+str2
3 . str2 = str1.Substring(str1.Length-str2.Length,str2.Length)
4 . str1 = str1.Substring(0,str1.Length-str2.Length)
Please refer below screenshot :