# Help with Number/String manipulation

I have a String “01021026888” and I have an int variable numOfTimes.
lets say the value of numOfTimes is 3, I want the string “01021026888” to be manipulated by replacing on the first 3 leftmost values, and this value must be unique in every instance. For example,
Given “01021026888” and numOfTimes = 4, the business wants a text file containing

11121026888
10121026888
23421026888
00121026888

the value of the first three leftmost digit does not matter as long as they are unique for each instance.

Could you maybe check with the below Expression :

``````(new Random).Next(Cint(Math.Pow(10,3)),CInt(Math.Pow(10,4))).ToString+textData.Substring(4)
``````

From Debug :

In place of 4 we can provide the variable so that it can be dynamic.

Here, `textData` is a string variable, you could convert your Integer value to string and using it we should be able to perform the above operation.

1 Like

@supermanPunch
Thanks, my workflow- see attached followed your instructions but it did not:

• Generate more than one object/row
• it replaced all of the numbers, the goal here is to only replace the first 3 digit for each occurrence.

The business rule is to acheive this
Given “01021026888” and numOfTimes = 4, the business wants a text file containing

11121026888
10121026888
23421026888
00121026888

workflow attached.
replaceFirst3Digits.zip (2.8 KB)

we can prepare for us a variable of DataType Random
myRandom | Default Value: new Random()

For a better Distribution we can slot in Big Numbers into smallers by using the Modulo Function
For a dynamic mod slot based on the length we do:

myModSlot | Int32 = CInt(“9”.PadRight(4,"9"c)) - we can dynamize 4 with an int Variable

The random part we can create by

and can merge the new part with the other part by using concat / substring etc.

When a distinct series is to create we would bring it within a do while and will repeat the loop, till we got X distinct random numbers

Check this:

``````Assigns:
str_input = "01021026888"
rd = new Random() (type: System.Object[])
list_resultList = New List(Of String) From {str_input}

While (list_resultList.Count < 4)
Assigns:
newString = (rd.Next(1000).ToString().PadLeft(3, "0"c)) & str_input.Substring(3)
Append Item to list activity to add newString to list_resultList
list_resultList  = list_resultList .Distinct().ToList()
counter = counter+1

For Each item In list_resultList
Use Append line activity to add currentItem to the text file
``````
1 Like

If the suggestions (Other) provided does not work for your case, could you maybe provide us another example with with `numOfTimes` as 3 and one more with `numOfTimes` as 4 ? Just so that we can clear the confusions and get the requirement understood.

@supermanPunch
Following this approach, I ran into some compile issues

do not missout the brackets
(myRandom…Mod 9999)<- .toString

@ppr @supermanPunch
I dont know what I’m doing wrong here. Is this where I’m assigning value to a random var using the assign activity? Or I’m I doing this all wrong?

replaceFirst3Digits.zip (3.1 KB)

there were a few corrections and adaptions to do as the given building blocks were not ported to the modelling

Variables

Flow:

myModSlot =

``````CInt("9".PadRight(RandomLength,"9"c))
``````

tmpNewValue =

``````(myRandom.Next() Mod myModSlot).ToString().PadLeft(RandomLength,"0"c) & strStart.Substring(RandomLength)
``````

ResultList =

``````ResultList.Append(tmpNewValue).Distinct().toList
``````

input & Result List

Find starter help here:
MainV2.xaml (9.6 KB)

1 Like

@supermanPunch @ppr @supriya117 Thanks all!

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