String Manipulation to add text in between a text file

I have a string like below.

StringValue =

"Random text line 1
Random text line2
Item URL: ’ ’
Random text line 3
Random text line 4 "

I need to update the Item URL (Which is blanks above) with a value that I get from Asset.

Hi @besakkiappan46

StringValue = "Random text line 1
Random text line2
Item URL: ’ ’
Random text line 3
Random text line 4 "

urlValue = "https://www.example.com"  // Replace this with the value you get from the Asset in UiPath
updatedString = StringValue.Replace("Item URL: ’ ’", "Item URL: " + urlValue)

@besakkiappan46

Get Asset (GetAsset)
AssetName: “your_asset_name” (replace with the name of your Asset)
Output: itemUrlValue

Assign stringValue
System.Text.RegularExpressions.Regex.Replace(stringValue, “Item URL: ’ ’”, "Item URL: " + itemUrlValue)

Log Message
"Updated String Value: " + stringValue

@besakkiappan46

You can use a simple String manipulation Function .Replace

inputStr="Random text line 1
Random text line2
Item URL: ’ ’
Random text line 3
Random text line 4 "

Link = “www.google.com
Below is the code
inputStr.Replace("’ ’",Link)

So the above code will replace single quotes to the link"

Below is the output

Hope it helps you out

@besakkiappan46

StringValue =

"Random text line 1
Random text line2
Item URL: ’*’
Random text line 3
Random text line 4 "

Assume Asset Output variable as str_URL

NewStringValue = StringValue.Replace(“*”, str_URL)

Cheers!

Hi @besakkiappan46

Use the Replace function with regular expressions. Check the below expression to insert the asset value in the Item URL

- Assign -> StringValue = "Random text line 1
                           Random text line2
                           Item URL: ’ ’
                           Random text line 3
                           Random text line 4 "
- Assign -> StringValue = System.Text.RegularExpressions.Regex.Replace(StrVar.ToString,"((?<=\’).*(?=\’))",AssetValue)

In the above expression StrVar is the String variable which stores the above data.
The AssetValue is a variable which contains the asset value (Output of get asset activity).

If you want to replace with single quotes also use the below one.

- Assign -> StringValue = System.Text.RegularExpressions.Regex.Replace(StrVar.ToString,"(’ ’)",AssetValue)

Hope it helps!!