# String manipulation with constant string length

**URL:** <https://forum.uipath.com/t/string-manipulation-with-constant-string-length/123193>\
**Category:** Help\
**Tags:** studio, terminal, system, activities\
**Created:** [2019 年 6 月 6 日午後 11:55 UTC](https://forum.uipath.com/t/string-manipulation-with-constant-string-length/123193 "2019-06-06T23:55:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manuvidesh](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@Manuvidesh](https://forum.uipath.com/u/Manuvidesh)\
**Post date:** [2019 年 6 月 6 日午後 11:55 UTC](https://forum.uipath.com/t/string-manipulation-with-constant-string-length/123193/1 "2019-06-06T23:55:30Z")

</div>

Hi everyone this is my first post, need help with string manipulation as i am working in terminal sessions its getting tricky.

i am getting a string with value (“29/HCGS/416813/001/PN”)  
i need to manipulate it so that the output should have “S”(constant) for every string value including SPACE " " and the given string. but the tricky part is only one of the “/” infront of “001” in string should be replaced by SPACE " ".  
The length of string gonna be constant(21).  
required final output should be like (“S 29/HCGS/416813 001/PN”)

Thanks

---

<div class="post-metadata">

**Author:** ![Michael\_Udhaya](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/michael_udhaya/32/69660_2.png) [@Michael\_Udhaya](https://forum.uipath.com/u/Michael_Udhaya)\
**Post date:** [2019 年 6 月 7 日午前 2:04 UTC](https://forum.uipath.com/t/string-manipulation-with-constant-string-length/123193/2 "2019-06-07T02:04:27Z")

</div>

Hi @Manuvidesh Welcome to UiPath Community,

If the string format and length is standard, then you can use

```auto
string str = “29/HCGS/416813/001/PN”;
str = "S " + str.Remove(14, 1).Insert(14, " ");

```

Note : the 14 was the index of “/” in string.

Otherwise you can use RegEx by finding 3rd occurrence and replacing it by Space.

Or use the String.ReplaceAt() method by using indexes.

Hope you will get sollutions.

TanQ,  
Michael Udhaya

---

<div class="post-metadata">

**Author:** ![aksh1yadav](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/aksh1yadav/32/135359_2.png) [@aksh1yadav](https://forum.uipath.com/u/aksh1yadav)\
**Post date:** [2019 年 6 月 7 日午前 3:58 UTC](https://forum.uipath.com/t/string-manipulation-with-constant-string-length/123193/3 "2019-06-07T03:58:36Z")

</div>

> [@Michael\_Udhaya](#):
>
> 29/HCGS/416813/001/PN

Hey @Manuvidesh

> [@Manuvidesh](#):
>
> The length of string gonna be constant(21).  
> required final output should be like (“S 29/HCGS/416813 001/PN”)

You can try this also even length will vary then also it will work.

```
String Str= "29/HCGS/416813/001/PN";

Int32 SecondLastIndexOfChar = Str.LastIndexOf("/",Str.LastIndexOf("/")-1);

String Result = "S "+Str.Remove(SecondLastIndexOfChar,1).Insert(SecondLastIndexOfChar," ")

WriteLine - Result // Output - S 29/HCGS/416813 001/PN

```

Regards…!!  
Aksh

---

<div class="post-metadata">

**Author:** ![Manuvidesh](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@Manuvidesh](https://forum.uipath.com/u/Manuvidesh)\
**Post date:** [2019 年 6 月 7 日午後 3:21 UTC](https://forum.uipath.com/t/string-manipulation-with-constant-string-length/123193/4 "2019-06-07T15:21:13Z")

</div>

Thanks aksh1yadav

---

<div class="post-metadata">

**Author:** ![Manuvidesh](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@Manuvidesh](https://forum.uipath.com/u/Manuvidesh)\
**Post date:** [2019 年 6 月 7 日午後 3:21 UTC](https://forum.uipath.com/t/string-manipulation-with-constant-string-length/123193/5 "2019-06-07T15:21:47Z")

</div>

Thanks Michael\_Udhaya

---

<div class="post-metadata">

**Author:** ![jOeyO](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/joeyo/32/176950_2.png) [@jOeyO](https://forum.uipath.com/u/jOeyO)\
**Post date:** [2019 年 8 月 6 日午後 11:13 UTC](https://forum.uipath.com/t/string-manipulation-with-constant-string-length/123193/6 "2019-08-06T23:13:10Z")

</div>

Keep it Simple …

inputString = “29/HCGS/416813/001/PN”  
outPutString = "S “+inputString.Substring(0,14)+” "+inputString.Substring(15,6)

---

<div class="post-metadata">

**Author:** ![pattyricarte](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/pattyricarte/32/81346_2.png) [@pattyricarte](https://forum.uipath.com/u/pattyricarte)\
**Post date:** [2019 年 8 月 7 日午前 3:09 UTC](https://forum.uipath.com/t/string-manipulation-with-constant-string-length/123193/7 "2019-08-07T03:09:14Z")

</div>

Hi @Manuvidesh

Also here i would like to share some thoughts of String manipulation.

> [@How to manipulate a part of string: Split, Trim, Substring, Replace, Remove, Left, Right](https://forum.uipath.com/t/how-to-manipulate-a-part-of-string-split-trim-substring-replace-remove-left-right/140180):
>
> Hi, if you are a beginner in the world of automation and would like to know how you can manipulate text based on the solutions available in the [VB.NET](http://VB.NET) code and using REGEX (regular expressions) then you are in the right place. In the topic below, you will learn how to easily extract data from any part of the search text using various methods. The topic includes solution examples with descriptions and graphics to better understand the topic for functions such as: Split Substring Left Right R…

cheers 😃

Happy learning 😃

---

<div class="post-metadata">

**Author:** ![jOeyO](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/joeyo/32/176950_2.png) [@jOeyO](https://forum.uipath.com/u/jOeyO)\
**Post date:** [2019 年 8 月 7 日午前 10:59 UTC](https://forum.uipath.com/t/string-manipulation-with-constant-string-length/123193/8 "2019-08-07T10:59:10Z")

</div>

This is great … I have been in the process of compiling a similar list.
