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!
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"))
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"))
Copy link to clipboard
Copied
Hi try,
How about my script?
John
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).
Copy link to clipboard
Copied
Hi try
a script about auto bookmark for pdf.
should I post all the details on the forum?
John
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.
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
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.
Copy link to clipboard
Copied
I hope everything works out, seems like an interesting hassle. Thank you for the help, by the way Try67
Copy link to clipboard
Copied
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