Please help with string manipulation

Hello!

How can I remove the end of a string if I am not sure what it will be?
Example, it could end in 3, 016 or P00004.
Modification No. 3
Modification No. 016
Modification No. P00004

I need to remove everything after Modification No. and add another variable.

Thank you!

@Jessica_Moseley

yourVariable = “Modification No. 016”

newVariable = yourVariable.Substring(0,16)

newVariable = “Modification No.”

Use an assign activity create a new string variable eg:

ResultsString = theStringVariableHoldingText.Replace(theStringVariableHoldingText.Split("."c)(1).toString, ". "+TheVariableyouAreReplacingWith)

1 Like

If it’s always going to say "Modification No. " why even bother removing the end of it? You don’t even need to read it at all, you can just hardcode in that portion of the string

I am hardcoding “Modification No.” but I need to remove the unknown value following it so I can replace it with a new value.

@Jessica_Moseley f you’re removing everything after Modificaiton No. I still don’t understand why you’d need to remove it at all? Instead you can just do: "Modification No. " + YourReplacementTextHere where YourReplacementTextHere is the string you want to insert. No need for reading the string prior and replacing

The replacement text does not remove what follows “Modification No.”

I see the logic but when I assign newVariable= “Modification No.” and then assign newVariable= myVariable.substring(0,16), it’s not removing what comes after Modification No. when I use my Replace Text activity

I am saying you don’t need to pull in any of the text that contains “Modification No.” or what follows. Instead, just hardcode the beginning of your output string to be “Modification No.” and then append whatever you want the new string text to be.

yourVariable should contain the text you are passing, example: “Modification No. P00004”

newVariable = yourVariable.Substring(0,16)

newVariable will then only ouput “Modification No.”
After you can use newVariable however you like.

I will not know what follows Modification No. when I am replacing it.

yourVariable = “Modification No. P00004”

newVariable2 = yourVariable.Substring(17)

newVariable2 will contain everything after "No. "

I want to remove everything after “No.”

I have myVariable= “Modification No.”
Assign newVariable= myVariable.substring(16)
Replace Text myVariable - myVariable + replacement text

The replacement text is there but so is P00004. How do I remove the P00004?

Do the thing @SenzoD is describing above.

ResultsString = theStringVariableHoldingText.Replace(theStringVariableHoldingText.Split("."c)(1).toString, ". "+TheVariableyouAreReplacingWith)

You could maybe get and extra “.” with the above, if so try:

ResultsString = theStringVariableHoldingText.Replace(theStringVariableHoldingText.Split("."c)(1).toString, " "+TheVariableyouAreReplacingWith)

@Jessica_Moseley can you let me know what your intended output string looks like like based on your 3 examples listed in your first post?

myVariable= “Modification No.”
Assign newVariable= myVariable.replace(myVariable.Split("."c)(1).tostring, ". "+VariableIamReplacingWith)
Replace Text myVariable - newVariable

Error Assign string cannot be of zero length

myVariable= “Modification No.”
intended output = myVariable + " " + VariableIamReplacingWith

You need to assign a value to VariableIamReplacingWith

VariableIamReplacingWith = "test123"

It has a value it’s pulling from an excel cell

Ok, just use this:

IntendedOutput = "Modification No. " + VariableIamReplacingWith

You don’t need to read the input variable or anything like that. Just type in the above only. No need to do any replacements or anything