# Replacing multiple items in a string

**URL:** <https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963>\
**Category:** Lists-Logic\
**Created:** [July 20, 2018, 11:01am UTC](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963 "2018-07-20T11:01:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ROY](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/roy/32/55244_2.png) [@ROY](https://forum.dynamobim.com/u/ROY)\
**Post date:** [July 20, 2018, 11:01am UTC](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963/1 "2018-07-20T11:01:55Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/5/35eef470a839ae5368077d9a2db99b9cabec21d3.png)

---

<div class="post-metadata">

**Author:** ![Alban\_de\_Chasteigner](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/alban_de_chasteigner/32/39650_2.png) [@Alban\_de\_Chasteigner](https://forum.dynamobim.com/u/Alban_de_Chasteigner)\
**Post date:** [July 20, 2018, 11:37am UTC](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963/2 "2018-07-20T11:37:13Z")

</div>

Hi @ROY,

You can use “String.ReplaceMultiple” from Clockwork

 ![Replace](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/f/8f51b2455f35772a024d369377ace3b04d4f444a.png)

---

<div class="post-metadata">

**Author:** ![mellouze](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mellouze](https://forum.dynamobim.com/u/mellouze)\
**Post date:** [July 20, 2018, 11:46am UTC](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963/3 "2018-07-20T11:46:47Z")

</div>

Hi Roy,

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

 ![Capture](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/9/f97326cee2777cd45b3144a4e25c8cf8a81471ff.PNG)

Best regards

---

<div class="post-metadata">

**Author:** ![ROY](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/roy/32/55244_2.png) [@ROY](https://forum.dynamobim.com/u/ROY)\
**Post date:** [July 20, 2018, 11:59am UTC](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963/4 "2018-07-20T11:59:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mellouze](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mellouze](https://forum.dynamobim.com/u/mellouze)\
**Post date:** [July 20, 2018, 12:04pm UTC](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963/5 "2018-07-20T12:04:21Z")

</div>

Sure thing 🙂 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;
};
```

---

<div class="post-metadata">

**Author:** ![ROY](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/roy/32/55244_2.png) [@ROY](https://forum.dynamobim.com/u/ROY)\
**Post date:** [July 20, 2018, 12:10pm UTC](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963/6 "2018-07-20T12:10:01Z")

</div>

Thanks! i got stuck somewhere and i cant figure it out 😕

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/1/119f2334ec8f1d27ac511271a0d140ddb35950ec.png)

---

<div class="post-metadata">

**Author:** ![mellouze](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mellouze](https://forum.dynamobim.com/u/mellouze)\
**Post date:** [July 20, 2018, 12:15pm UTC](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963/7 "2018-07-20T12:15:18Z")

</div>

What is the error saying ?

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

---

<div class="post-metadata">

**Author:** ![ROY](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/roy/32/55244_2.png) [@ROY](https://forum.dynamobim.com/u/ROY)\
**Post date:** [July 20, 2018, 12:15pm UTC](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963/8 "2018-07-20T12:15:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ROY](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/roy/32/55244_2.png) [@ROY](https://forum.dynamobim.com/u/ROY)\
**Post date:** [July 20, 2018, 12:17pm UTC](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963/9 "2018-07-20T12:17:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mellouze](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mellouze](https://forum.dynamobim.com/u/mellouze)\
**Post date:** [July 20, 2018, 12:18pm UTC](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963/10 "2018-07-20T12:18:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ROY](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/roy/32/55244_2.png) [@ROY](https://forum.dynamobim.com/u/ROY)\
**Post date:** [July 20, 2018, 12:20pm UTC](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963/11 "2018-07-20T12:20:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Alban\_de\_Chasteigner](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/alban_de_chasteigner/32/39650_2.png) [@Alban\_de\_Chasteigner](https://forum.dynamobim.com/u/Alban_de_Chasteigner)\
**Post date:** [July 20, 2018, 12:24pm UTC](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963/12 "2018-07-20T12:24:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ROY](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/roy/32/55244_2.png) [@ROY](https://forum.dynamobim.com/u/ROY)\
**Post date:** [July 20, 2018, 12:24pm UTC](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963/13 "2018-07-20T12:24:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Alban\_de\_Chasteigner](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/alban_de_chasteigner/32/39650_2.png) [@Alban\_de\_Chasteigner](https://forum.dynamobim.com/u/Alban_de_Chasteigner)\
**Post date:** [July 20, 2018, 12:33pm UTC](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963/14 "2018-07-20T12:33:45Z")

</div>

It’s the same with an excel file.

 ![From%20excel](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/6/162af586e8da040e1b054c7098a3093193b991e1.png)

---

<div class="post-metadata">

**Author:** ![ROY](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/roy/32/55244_2.png) [@ROY](https://forum.dynamobim.com/u/ROY)\
**Post date:** [July 20, 2018, 12:57pm UTC](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963/15 "2018-07-20T12:57:17Z")

</div>

Thanks its working!!

---

<div class="post-metadata">

**Author:** ![ROY](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/roy/32/55244_2.png) [@ROY](https://forum.dynamobim.com/u/ROY)\
**Post date:** [July 21, 2018, 7:20am UTC](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963/16 "2018-07-21T07:20:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ROY](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/roy/32/55244_2.png) [@ROY](https://forum.dynamobim.com/u/ROY)\
**Post date:** [July 21, 2018, 7:20am UTC](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963/17 "2018-07-21T07:20:51Z")

</div>

its a good alternative though. thanks for help.

---

<div class="post-metadata">

**Author:** ![Vikram\_Subbaiah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vikram_subbaiah/32/50797_2.png) [@Vikram\_Subbaiah](https://forum.dynamobim.com/u/Vikram_Subbaiah)\
**Post date:** [July 21, 2018, 8:19am UTC](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963/18 "2018-07-21T08:19:56Z")

</div>

@ROY Other possible OOTB approaches

 ![stringMulRep1](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/1/910a7cc93101846308b1b1eea4e3965d806c042b.png)

 ![stringMulRep2](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/5/75f85720abbcbb896ff0a268f996f787b7878458.png)

---

<div class="post-metadata">

**Author:** ![Ewan\_Opie](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ewan_opie/32/77070_2.png) [@Ewan\_Opie](https://forum.dynamobim.com/u/Ewan_Opie)\
**Post date:** [July 21, 2018, 8:34am UTC](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963/19 "2018-07-21T08:34:01Z")

</div>

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;
};
```

---

<div class="post-metadata">

**Author:** ![ROY](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/roy/32/55244_2.png) [@ROY](https://forum.dynamobim.com/u/ROY)\
**Post date:** [July 21, 2018, 9:34am UTC](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963/20 "2018-07-21T09:34:26Z")

</div>

Nice. thanks!!

[Next page](https://forum.dynamobim.com/t/replacing-multiple-items-in-a-string/23963.md?page=2)
