Skip to main content
Ryan_Oliver_02445
Known Participant
February 4, 2019
Answered

How to remove white space from a string?

  • February 4, 2019
  • 3 replies
  • 2681 views

Good evening, I am trying to find a way to remove white space from a string in JS, but as of right now, I have found no solution.

Here is some example code:

var Array = [];

var foo = "Hello";

var voo = "World";

if (foo != null){

  Array.push(foo);

}

if (voo !- null){

  Array.push(voo):

}

console.println(Array.join(', ');

\\Results: "Hello , World"\\

\\The space left of the comma should not be there\\

That really is the short of it.

Is there any way to remove spaces from a string, or at least from an Array?

That, or remove the space from the left of the comma?

Thank you!

This topic has been closed for replies.
Correct answer try67

Your code contains multiple errors (at least four), but after fixing it I'm not getting the result you're getting. It returns "Hello, World".

But if you want to trim a string you can use this code:

var s = "  Hi ";

s = s.replace(/^\s*/, "").replace(/\s*$/, "");

console.println(s.toSource()); // returns (new String("Hi"))

3 replies

Inspiring
February 5, 2019

Your script don't event past the license error,

it means first step.

I have test nothing about the auto bookmark.

waht I want just the script.

I don't want to make the payment and received nothing.

John

try67
Community Expert
Community Expert
February 5, 2019

That means you provided me with the wrong username. Anyway, please do not post here any more. It's not relevant to this question.

Send me a reply by email only.

Ryan_Oliver_02445
Known Participant
February 5, 2019

I hope everything works out, seems like an interesting hassle.  Thank you for the help, by the way Try67

Inspiring
February 5, 2019

Hi try

a script about auto bookmark for pdf.

should I post all the details on the forum?

John

try67
Community Expert
Community Expert
February 5, 2019

Is that a threat? You still owe me for that development, if I remember correctly. At any rate, let's discuss it privately, as it's really not relevant for the other people on this forum.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
February 4, 2019

Your code contains multiple errors (at least four), but after fixing it I'm not getting the result you're getting. It returns "Hello, World".

But if you want to trim a string you can use this code:

var s = "  Hi ";

s = s.replace(/^\s*/, "").replace(/\s*$/, "");

console.println(s.toSource()); // returns (new String("Hi"))

Inspiring
February 5, 2019

Hi try,

How about my script?

John

try67
Community Expert
Community Expert
February 5, 2019

I don't know which script you're referring to. And please don't "hijack" someone else's thread for your questions...

If you want to contact me privately you can do so by sending me a message here, or via email (try6767 at gmail.com).