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

How to remove white space from a string?

Explorer ,
Feb 04, 2019 Feb 04, 2019

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
2.2K
Translate
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"))

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

Translate
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

Hi try,

How about my script?

John

Translate
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

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

Translate
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

Hi try

a script about auto bookmark for pdf.

should I post all the details on the forum?

John

Translate
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

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.

Translate
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

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

Translate
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

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.

Translate
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

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

Translate
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
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

Translate
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