0

I am taking input in the form of a string in a google spreadsheet (through forms). I need to make sure that there are no white spaces before and after this string...

I've tried using Javascript command

mystring = mystring.replace(/(^\s+|\s+$)/g,' ');

but it doesnt seem to work here.

Please help

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
al_capone
  • 46
  • 1
  • 4

2 Answers2

1

If your string is inside a google docs sheet, can you just apply the TRIM() function to it before importing to your application? TRIM() does exactly what you are looking for, plus removes duplicated intermediate spaces that trouble formatting.

0

how about this?

s.replace(/\s+/g, ' ');

EDIT:

mystring = mystring.replace(/(^\s+|\s+$)/g,' ');

This will remove all spaces from the beginning or end of the string...

Ofir Hadad
  • 1,800
  • 3
  • 26
  • 47