Replacing multiple items in a string

i am trying to swipe multiple items in a string but its partially working.

Hi @ROY,

You can use “String.ReplaceMultiple” from Clockwork

Hi Roy,

You can also consider using DesignScript if you don’t want to download a package.

Best regards

Thank you @mellouze. Can i copy this code block?

Sure thing :slight_smile: You might want to replace the while loop with a for loop.

str;
search;
replace;
n = List.Count(search);
c = [Imperative]{
	i=0;
	result = str;
	while(i<n){
		result = String.Replace(result,search[i],replace[i]);
		i = i+1;
	}
	return = result;
};

Thanks! i got stuck somewhere and i cant figure it out :confused:

What is the error saying ?

Also, for some reason, Dynamo is interpreting List as a variable in your graph.

it says: Warning: Internal error, please report: Dereferencing a non-pointer.

i was using dynamo 1.3 which is showing error
but i tried same with 2.0.1 now this code block is working

1 Like

I always worked on Dynamo 2.0.1, unfortunately i cannot fix the code for 1.3 :confused:

thats fine. Thanks for help. one more thing. Can i use nodes instead? is it possible?

Did you try String.ReplaceMultiple ?
It works like a charm.

yes i tried but the problem is end of the day i need to get string from excel. i am not sure if it will work or not.

It’s the same with an excel file.

2 Likes

Thanks its working!!

i finally working with this and its working like a charm.

its a good alternative though. thanks for help.

@ROY Other possible OOTB approaches

2 Likes

If you replace List with DSCore.List it should work.

str;
search;
replace;
n = DSCore.List.Count(search);
c = [Imperative]{
	i=0;
	result = str;
	while(i<n){
		result = String.Replace(result,search[i],replace[i]);
		i = i+1;
	}
	return = result;
};
2 Likes

Nice. thanks!!

1 Like