Use of Trim Method to Remove Spaces In a String

like if I have a string 609 056
and I want to remove the space between 9 and 0 to make it a single no , can I use trim here

hi @Gaurav07

Can you please elaborate on your query?

How do you want the output as ?

I am scraping a number in cirtix and the original no is like 609897 but sometimes it is scraped as 609 897, a space is coming between so if I use .trim then the space wont come right?

also I want to know other applications of trim meth9od

Hi @Gaurav07

use the following method to get the desired reply :slight_smile:

Do let me know in case of query :slight_smile:

1 Like

Hello @Gaurav07

Application of Trim will remove spaces only in the front of the string and at the end of the string… As you might be aware by now, trim has three functions.
Left trim - remove spaces in front of the string
Right trim - remove spaces at the end of the string
Trim - remove spaces in both front and at the end.

If there are spaces in the middle of the string, just like in your case, these will not be captured by the trim command. If you want to replace those, then you need to use the string.Replace function which @Shubham_Varshney just mentioned in the previous comment… It will replace all the spaces in the given string irrespective of the location it is in…

2 Likes

You need to use str.Replace(" “,”") to do the task @Gaurav07