Converting the string to the integer

hi all,
Actually i have a string like
“shyam is is is a good good developer”
i have to replace
shyam=1
is=2
a=3
good=4
developer=5

how can i do this please explain.
thankyou

Hi @shailaja_reddy ,

You can use below code,

YourStr(Varible type string) = "shyam is is is a good good developer"

newStr(Variable type String) = YourStr.Replace("shyam","1").Replace("is","2").Replace("a","3").Replace("good","4").Replace("developer","5")

Hope this helps :slight_smile:

im getting the error

Hi @shailaja_reddy ,

Can you share error screenshot?

can we use for loop for this

Hi @shailaja_reddy ,

You can perform this operation in single assign activity as below,
newStr(Variable type String) = YourStr.Replace("shyam","1").Replace("is","2").Replace("a","3").Replace("good","4").Replace("developer","5")

Screenshots:-

ya im doing like this only

Hi @shailaja_reddy ,

What error are you getting?

Hi @shailaja_reddy ,

You could create a Dictionary out of this mapping as the keys will be unique.

We can then perform a Replace of the Text accordingly by substituting it’s assigned value in place of the key.

I have used a Excel sheet, placing the key values and then converted the Key Value columns into a Dictionary :
image

Converting the Datatable to Dictionary :

KeyValueDict = DT.AsEnumerable.ToDictionary(Function(x)x("Key").ToString,Function(x)x("Value").ToString)

Next, we can use the Input String and replace the value accordingly using the below Expression :

String.Join(" ",Split("shyam is is is a good good developer").Select(Function(x)if(KeyValueDict.ContainsKey(x),KeyValueDict(x),x)))

image

If the word is not present as a key :
image

Note: I have edited the Expression to replace "" with x

1 Like

@shailaja_reddy , it seems you are using some extra colons.

Can you display your whole expression?

hi
how can we do this by using for loop?

@shailaja_reddy

use strInInput.replace(“is”,“2”).Replace(“a”,“3”) so on.

Hope this helps
Cheers.

i want this solution by using for loop

its not working

@shailaja_reddy

image

Hope this helps
Cheers

@shailaja_reddy ,

We could try it using the below way :

Expression in the Assign :

PdfText = If(KeyValueDict.ContainsKey(item),PdfText.Replace(item,KeyValueDict(item)),PdfText)

Do note that the Dictionary is to be created as mentioned in the previous post.

ya thank you