Latif
(Robin)
January 15, 2026, 10:46am
1
hi
I want to append data into a variable on a specifik place.
varibale1 = Michael jackson, 29081958 (256), Gary (75), USA (13)
Now after (256) and before “,” I want to add “Space (King of Pop)”
like = Michael jackson, 29081958 (256) (King of Pop), Gary (75), USA (13)
How can use split or append together? OR do i need to use something else?
Hi @Latif ,
Assign Activity:
variable1 =
variable1.Insert(variable1.IndexOf("(256)") + 4, " (King of Pop)")
How it works: Finds end of “(256)” and inserts your text right before comma. no split needed.
Test first in Debug mode
@Latif
Is your string going to be same or dynamic? if same then go with the IndexOf option to get the exact index at which you have to append your value.
If string is going to be dynamic, you will have to find a pattern and then using RegEx you can replace or append the desired value.
Latif
(Robin)
January 15, 2026, 11:24am
4
As its differet from person to person so it will never be same.. (256) that was just an example.
the whole variable will contain data rekated to the spcifik person. so i need something with finding first bracket og last part for first brackets and then replace or add
Hi @Latif
Try like below Example:
System.Text.RegularExpressions.Regex.Replace(variable1, @“)(?=,)”, “) (King of Pop)”)
This finds ) before the first comma and appends your text. For dynamic text, replace “King of Pop” with your variable. No need to split; regex is best for this case.
If helpful, mark as solution. Happy automation with UiPath
@Latif
Try this RegeX
variable1 = System.Text.RegularExpressions.Regex.Replace(variable1, "(d+)", "$0 (King of Pop)")
Latif
(Robin)
January 15, 2026, 11:49am
8
sorry but this is not write as i read..
I want to find the specifik place and then append the text. so this will never work.
Two Assign Activities (works for ANY person data):
*1st Assign:
pos = variable1.IndexOf("(")
*2nd Assign:
variable1 = variable1.Insert(pos + variable1.IndexOf(")", pos) + 1, " (King of Pop)")
@Latif
No, pos must be an Integer variable!
Create variable pos as type Int32 (not String).
@Latif
Hey! Multiple Assign can’t reference variables created in the same activity. That’s your error!
Use 2 SEPARATE Assign activities instead
**1st Assign Activity:**
To: `pos` (Int32 variable)
Value: `variable1.IndexOf("(")`
**2nd Assign Activity:**
To: `variable1` (String variable)
Value: `variable1.Insert(pos + variable1.IndexOf(")", pos) + 1, " (King of Pop)")`
Why Multiple Assign failed: It evaluates ALL lines simultaneously, so pos doesn’t exist yet in the 2nd line
Latif
(Robin)
January 15, 2026, 1:49pm
14
Now it gives another issue
Latif
(Robin)
January 15, 2026, 1:52pm
15
Its working now.. Index value needed End brackets and not start brackets.
Than it solved the issue.
@Latif
The error happens because IndexOf(“)”) returns -1 (not found), making startIndex negative.
Assign Activities:
**1st Assign:** posOpen = variable1.IndexOf("(")
**2nd Assign:** posClose = If(posOpen > -1, variable1.IndexOf(")", posOpen), -1)
**3rd Assign:** If(posClose > -1, variable1 = variable1.Insert(posClose + 1, " (King of Pop)"), "")
Your string length 52 means no ) after position 57 → fixed now.
Latif
(Robin)
January 15, 2026, 2:00pm
17
I did like this.
Assign [Activities]
**1st Assign:** varIndex = variable1.IndexOf(")")
**2nd Assign:** varName = varName.Insert(varName.indexOf(")", varIndex) + 1, " (King of Pop)")
Result
Is this still a correct way?
Yes, its correct and better
postwick
(Paul Ostwick)
January 15, 2026, 2:19pm
19
This should not be a string variable. You should be using a variable that is datatype IEnumerable(of String) and set its default to New List(Of String). Then you can do…
Assign yourVarName = yourVarName.Concat({“New value to add to the list”})
That will add a value to the list.
Or you can do
Assign yourVarName = yourVarName.Concat({“New value to add”,“Another new value”,“Third new value”})
To add more than one value to the list.
Then you can do sorting and things on the list to change the order.
Wouldn’t it be most simplistic to just use split if the structure is always the second comma?
Assign var1 = “Michael jackson, 29081958 (256), Gary (75), USA (13)”
Assign var2 = “ (King of Pop)”
Assign var1 =
var1.Split(","c)(0) & “, " &
var1.Split(”,"c)(1) & var2 & “, " &
var1.Split(”,"c)(2) & “, " &
var1.Split(”,"c)(3)
And if this modification is to be used for more variables:
(pic from Studio v 2025+)