• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to remove white space from a string?

Explorer ,
Feb 04, 2019 Feb 04, 2019

Copy link to clipboard

Copied

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!

TOPICS
Acrobat SDK and JavaScript , Windows

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 04, 2019 Feb 04, 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"))

Votes

Translate

Translate
Community Expert ,
Feb 04, 2019 Feb 04, 2019

Copy link to clipboard

Copied

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"))

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 05, 2019 Feb 05, 2019

Copy link to clipboard

Copied

Hi try,

How about my script?

John

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 05, 2019 Feb 05, 2019

Copy link to clipboard

Copied

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).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 05, 2019 Feb 05, 2019

Copy link to clipboard

Copied

Hi try

a script about auto bookmark for pdf.

should I post all the details on the forum?

John

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 05, 2019 Feb 05, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 05, 2019 Feb 05, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 05, 2019 Feb 05, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 05, 2019 Feb 05, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 05, 2019 Feb 05, 2019

Copy link to clipboard

Copied

LATEST

In relation to your answer, I got to messing around with my program, and found that trimming the white-space from a string before pushing it into an array worked very well

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines