Skip to main content

How to remove the last space from a string using regex?

HI @Vinothkumar.N ,

 

In general, you can do the following method to remove white spaces.

Search for ^r \t]+  and replace with empty value → To trim leading White space

Search for c \t]+$ and replace with empty value  → To trim trailing White space

 

Else, simply put .trim with your Variable name to automatically trim down the white space.

 

Could you please provide an example to understand your query?


Hi @Vinothkumar.N ,

If you want to remove last space from a string you can use trim action under string package.


 Example HST#320#HISTORY OF MICHIGAN 3#3.0

Before the last space I need to add an # instead of space


You mean,

like this HST#320#HISTORY OF MICHIGAN#3#3.0

or

like this HST#320#HISTORY OF MICHIGAN 3#3.0#


Like 1st option


If that’s the case, then you can split the text HST#320#HISTORY OF MICHIGAN and 3#3.0 assign it to separate variables. Then you can use g \t]+$ and replace with #. Finally join them.


Ok, Thanks for your help I will try this


Reply