Split/Strip a set of lines on encountering newline or comma
I have a set of lines in a textpad.
Eg:
643 ABCF aksdjgk 1q25hgn
239056 dsgkn 32968, 39859 ewktgklh, 35927369
9689846 dklsghdkls 23-608 dsklgnk
ewth834056 sidtguoi,235907 sdkgji,25689-8, 29067490,wtyuoew
How can I read this using python and have the text split into different list values on newline as well as ,
(comma)?
For instance, the output for the example text should come out as
643 ABCF aksdjgk 1q25hgn
239056 dsgkn 32968,
39859 ewktgklh,
35927369
9689846 dklsghdkls 23-608 dsklgnk
ewth834056 sidtguoi,
235907 sdkgji,
25689-8,
29067490,
wtyuoew
python
add a comment |
I have a set of lines in a textpad.
Eg:
643 ABCF aksdjgk 1q25hgn
239056 dsgkn 32968, 39859 ewktgklh, 35927369
9689846 dklsghdkls 23-608 dsklgnk
ewth834056 sidtguoi,235907 sdkgji,25689-8, 29067490,wtyuoew
How can I read this using python and have the text split into different list values on newline as well as ,
(comma)?
For instance, the output for the example text should come out as
643 ABCF aksdjgk 1q25hgn
239056 dsgkn 32968,
39859 ewktgklh,
35927369
9689846 dklsghdkls 23-608 dsklgnk
ewth834056 sidtguoi,
235907 sdkgji,
25689-8,
29067490,
wtyuoew
python
Your expected output has all the spaces intact, but the title mentions stripping. Which one is it?
– Mad Physicist
Jan 2 at 4:29
Sorry, the spaces at the end of the lines can be trimmed..
– asimo
Jan 2 at 4:31
add a comment |
I have a set of lines in a textpad.
Eg:
643 ABCF aksdjgk 1q25hgn
239056 dsgkn 32968, 39859 ewktgklh, 35927369
9689846 dklsghdkls 23-608 dsklgnk
ewth834056 sidtguoi,235907 sdkgji,25689-8, 29067490,wtyuoew
How can I read this using python and have the text split into different list values on newline as well as ,
(comma)?
For instance, the output for the example text should come out as
643 ABCF aksdjgk 1q25hgn
239056 dsgkn 32968,
39859 ewktgklh,
35927369
9689846 dklsghdkls 23-608 dsklgnk
ewth834056 sidtguoi,
235907 sdkgji,
25689-8,
29067490,
wtyuoew
python
I have a set of lines in a textpad.
Eg:
643 ABCF aksdjgk 1q25hgn
239056 dsgkn 32968, 39859 ewktgklh, 35927369
9689846 dklsghdkls 23-608 dsklgnk
ewth834056 sidtguoi,235907 sdkgji,25689-8, 29067490,wtyuoew
How can I read this using python and have the text split into different list values on newline as well as ,
(comma)?
For instance, the output for the example text should come out as
643 ABCF aksdjgk 1q25hgn
239056 dsgkn 32968,
39859 ewktgklh,
35927369
9689846 dklsghdkls 23-608 dsklgnk
ewth834056 sidtguoi,
235907 sdkgji,
25689-8,
29067490,
wtyuoew
python
python
edited Jan 2 at 6:40
asimo
asked Jan 2 at 4:15
asimoasimo
610213
610213
Your expected output has all the spaces intact, but the title mentions stripping. Which one is it?
– Mad Physicist
Jan 2 at 4:29
Sorry, the spaces at the end of the lines can be trimmed..
– asimo
Jan 2 at 4:31
add a comment |
Your expected output has all the spaces intact, but the title mentions stripping. Which one is it?
– Mad Physicist
Jan 2 at 4:29
Sorry, the spaces at the end of the lines can be trimmed..
– asimo
Jan 2 at 4:31
Your expected output has all the spaces intact, but the title mentions stripping. Which one is it?
– Mad Physicist
Jan 2 at 4:29
Your expected output has all the spaces intact, but the title mentions stripping. Which one is it?
– Mad Physicist
Jan 2 at 4:29
Sorry, the spaces at the end of the lines can be trimmed..
– asimo
Jan 2 at 4:31
Sorry, the spaces at the end of the lines can be trimmed..
– asimo
Jan 2 at 4:31
add a comment |
2 Answers
2
active
oldest
votes
Try using re.sub
, and replace all commas with comma followed by a newline:
result = re.sub(',s*', ',n', input)
Note that we actually match ,s*
, to remove any whitespace which might occur after a comma separator.
1
Op keeps all the whitespace after the comma, despite what the title implies. +1 regardless
– Mad Physicist
Jan 2 at 4:29
@MadPhysicist You're right.
– Tim Biegeleisen
Jan 2 at 4:35
Not that OP wants this (after clarification), but you can replace with ` '\0n'` to keep the spaces. I haven't tested, but\0
might actually have to be\g<0>
to work properly.
– Mad Physicist
Jan 2 at 4:40
Apologies, i have just edited my required output..
– asimo
Jan 2 at 6:34
My answer appears to cover your expected output.
– Tim Biegeleisen
Jan 2 at 6:41
add a comment |
Assuming that "textpad" means text file, you have a couple of options. For a small file like the one shown, the easiest solution would be to read
in the entire file as a string, and replace the commas with a comma + newline, as @TimBiegeleisen's answer shows.
For larger files, this may not be a good option due to memory constraints. In that case, and for the sake of generality, I like to iterate over the lines of a file. Here is a fairly simple generator that behaves like a normal file iterator, but also splits on commas:
from itertools import zip_longest, repeat
import re
def spliterator(file):
for line in file:
segments = re.split(r',s*', line)
ends = repeat(',n', len(segments) - 1)
for item in zip_longest(segments, ends, fillvalue=''):
yield ''.join(item)
It would be pretty simple to make this accept the split pattern as an argument, optionally keep the trailing spaces, and return the whole line with newline characters inserted.
Using the generator is simple, since it just wraps a normal file object or any other iterable of lines:
with open('textpad.txt') as file:
print(''.join(spliterator(file)))
Here is an IDEOne link with a demo.
To get the contents of the whole file as though read in by readlines
, just wrap in list
:
lines = list(spliterator(file))
To write back to an open output file, use writelines
directly:
output.writelines(spliterator(file))
Apologies, i have just edited my required output..
– asimo
Jan 2 at 6:34
@Asimo. Please don't change your question after you've received valid answers. Instead, select an answer and ask another question if you have to.
– Mad Physicist
Jan 2 at 6:38
Let me revert back..Sorry for the hassle.. I have anways found a workaround to get the output in my desired format using your answer.. simply adding with open(r'H:Messengertest_Nov2.txt') as file: lines = ''.join(spliterator(file)) lines2 = lines.splitlines()
– asimo
Jan 2 at 6:39
@Asimo. The change you made is something you should be able to figure out in your own, or at least attempt, given the answers posted here.
– Mad Physicist
Jan 2 at 6:39
@asimo. Why not justlist(spliterator(file))
? No need for the extra hoops. Or you could just use the generator directly. I'm guessing you don't actually need the list.
– Mad Physicist
Jan 2 at 6:41
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001125%2fsplit-strip-a-set-of-lines-on-encountering-newline-or-comma%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try using re.sub
, and replace all commas with comma followed by a newline:
result = re.sub(',s*', ',n', input)
Note that we actually match ,s*
, to remove any whitespace which might occur after a comma separator.
1
Op keeps all the whitespace after the comma, despite what the title implies. +1 regardless
– Mad Physicist
Jan 2 at 4:29
@MadPhysicist You're right.
– Tim Biegeleisen
Jan 2 at 4:35
Not that OP wants this (after clarification), but you can replace with ` '\0n'` to keep the spaces. I haven't tested, but\0
might actually have to be\g<0>
to work properly.
– Mad Physicist
Jan 2 at 4:40
Apologies, i have just edited my required output..
– asimo
Jan 2 at 6:34
My answer appears to cover your expected output.
– Tim Biegeleisen
Jan 2 at 6:41
add a comment |
Try using re.sub
, and replace all commas with comma followed by a newline:
result = re.sub(',s*', ',n', input)
Note that we actually match ,s*
, to remove any whitespace which might occur after a comma separator.
1
Op keeps all the whitespace after the comma, despite what the title implies. +1 regardless
– Mad Physicist
Jan 2 at 4:29
@MadPhysicist You're right.
– Tim Biegeleisen
Jan 2 at 4:35
Not that OP wants this (after clarification), but you can replace with ` '\0n'` to keep the spaces. I haven't tested, but\0
might actually have to be\g<0>
to work properly.
– Mad Physicist
Jan 2 at 4:40
Apologies, i have just edited my required output..
– asimo
Jan 2 at 6:34
My answer appears to cover your expected output.
– Tim Biegeleisen
Jan 2 at 6:41
add a comment |
Try using re.sub
, and replace all commas with comma followed by a newline:
result = re.sub(',s*', ',n', input)
Note that we actually match ,s*
, to remove any whitespace which might occur after a comma separator.
Try using re.sub
, and replace all commas with comma followed by a newline:
result = re.sub(',s*', ',n', input)
Note that we actually match ,s*
, to remove any whitespace which might occur after a comma separator.
edited Jan 2 at 5:03
answered Jan 2 at 4:18
Tim BiegeleisenTim Biegeleisen
230k1395147
230k1395147
1
Op keeps all the whitespace after the comma, despite what the title implies. +1 regardless
– Mad Physicist
Jan 2 at 4:29
@MadPhysicist You're right.
– Tim Biegeleisen
Jan 2 at 4:35
Not that OP wants this (after clarification), but you can replace with ` '\0n'` to keep the spaces. I haven't tested, but\0
might actually have to be\g<0>
to work properly.
– Mad Physicist
Jan 2 at 4:40
Apologies, i have just edited my required output..
– asimo
Jan 2 at 6:34
My answer appears to cover your expected output.
– Tim Biegeleisen
Jan 2 at 6:41
add a comment |
1
Op keeps all the whitespace after the comma, despite what the title implies. +1 regardless
– Mad Physicist
Jan 2 at 4:29
@MadPhysicist You're right.
– Tim Biegeleisen
Jan 2 at 4:35
Not that OP wants this (after clarification), but you can replace with ` '\0n'` to keep the spaces. I haven't tested, but\0
might actually have to be\g<0>
to work properly.
– Mad Physicist
Jan 2 at 4:40
Apologies, i have just edited my required output..
– asimo
Jan 2 at 6:34
My answer appears to cover your expected output.
– Tim Biegeleisen
Jan 2 at 6:41
1
1
Op keeps all the whitespace after the comma, despite what the title implies. +1 regardless
– Mad Physicist
Jan 2 at 4:29
Op keeps all the whitespace after the comma, despite what the title implies. +1 regardless
– Mad Physicist
Jan 2 at 4:29
@MadPhysicist You're right.
– Tim Biegeleisen
Jan 2 at 4:35
@MadPhysicist You're right.
– Tim Biegeleisen
Jan 2 at 4:35
Not that OP wants this (after clarification), but you can replace with ` '\0n'` to keep the spaces. I haven't tested, but
\0
might actually have to be \g<0>
to work properly.– Mad Physicist
Jan 2 at 4:40
Not that OP wants this (after clarification), but you can replace with ` '\0n'` to keep the spaces. I haven't tested, but
\0
might actually have to be \g<0>
to work properly.– Mad Physicist
Jan 2 at 4:40
Apologies, i have just edited my required output..
– asimo
Jan 2 at 6:34
Apologies, i have just edited my required output..
– asimo
Jan 2 at 6:34
My answer appears to cover your expected output.
– Tim Biegeleisen
Jan 2 at 6:41
My answer appears to cover your expected output.
– Tim Biegeleisen
Jan 2 at 6:41
add a comment |
Assuming that "textpad" means text file, you have a couple of options. For a small file like the one shown, the easiest solution would be to read
in the entire file as a string, and replace the commas with a comma + newline, as @TimBiegeleisen's answer shows.
For larger files, this may not be a good option due to memory constraints. In that case, and for the sake of generality, I like to iterate over the lines of a file. Here is a fairly simple generator that behaves like a normal file iterator, but also splits on commas:
from itertools import zip_longest, repeat
import re
def spliterator(file):
for line in file:
segments = re.split(r',s*', line)
ends = repeat(',n', len(segments) - 1)
for item in zip_longest(segments, ends, fillvalue=''):
yield ''.join(item)
It would be pretty simple to make this accept the split pattern as an argument, optionally keep the trailing spaces, and return the whole line with newline characters inserted.
Using the generator is simple, since it just wraps a normal file object or any other iterable of lines:
with open('textpad.txt') as file:
print(''.join(spliterator(file)))
Here is an IDEOne link with a demo.
To get the contents of the whole file as though read in by readlines
, just wrap in list
:
lines = list(spliterator(file))
To write back to an open output file, use writelines
directly:
output.writelines(spliterator(file))
Apologies, i have just edited my required output..
– asimo
Jan 2 at 6:34
@Asimo. Please don't change your question after you've received valid answers. Instead, select an answer and ask another question if you have to.
– Mad Physicist
Jan 2 at 6:38
Let me revert back..Sorry for the hassle.. I have anways found a workaround to get the output in my desired format using your answer.. simply adding with open(r'H:Messengertest_Nov2.txt') as file: lines = ''.join(spliterator(file)) lines2 = lines.splitlines()
– asimo
Jan 2 at 6:39
@Asimo. The change you made is something you should be able to figure out in your own, or at least attempt, given the answers posted here.
– Mad Physicist
Jan 2 at 6:39
@asimo. Why not justlist(spliterator(file))
? No need for the extra hoops. Or you could just use the generator directly. I'm guessing you don't actually need the list.
– Mad Physicist
Jan 2 at 6:41
add a comment |
Assuming that "textpad" means text file, you have a couple of options. For a small file like the one shown, the easiest solution would be to read
in the entire file as a string, and replace the commas with a comma + newline, as @TimBiegeleisen's answer shows.
For larger files, this may not be a good option due to memory constraints. In that case, and for the sake of generality, I like to iterate over the lines of a file. Here is a fairly simple generator that behaves like a normal file iterator, but also splits on commas:
from itertools import zip_longest, repeat
import re
def spliterator(file):
for line in file:
segments = re.split(r',s*', line)
ends = repeat(',n', len(segments) - 1)
for item in zip_longest(segments, ends, fillvalue=''):
yield ''.join(item)
It would be pretty simple to make this accept the split pattern as an argument, optionally keep the trailing spaces, and return the whole line with newline characters inserted.
Using the generator is simple, since it just wraps a normal file object or any other iterable of lines:
with open('textpad.txt') as file:
print(''.join(spliterator(file)))
Here is an IDEOne link with a demo.
To get the contents of the whole file as though read in by readlines
, just wrap in list
:
lines = list(spliterator(file))
To write back to an open output file, use writelines
directly:
output.writelines(spliterator(file))
Apologies, i have just edited my required output..
– asimo
Jan 2 at 6:34
@Asimo. Please don't change your question after you've received valid answers. Instead, select an answer and ask another question if you have to.
– Mad Physicist
Jan 2 at 6:38
Let me revert back..Sorry for the hassle.. I have anways found a workaround to get the output in my desired format using your answer.. simply adding with open(r'H:Messengertest_Nov2.txt') as file: lines = ''.join(spliterator(file)) lines2 = lines.splitlines()
– asimo
Jan 2 at 6:39
@Asimo. The change you made is something you should be able to figure out in your own, or at least attempt, given the answers posted here.
– Mad Physicist
Jan 2 at 6:39
@asimo. Why not justlist(spliterator(file))
? No need for the extra hoops. Or you could just use the generator directly. I'm guessing you don't actually need the list.
– Mad Physicist
Jan 2 at 6:41
add a comment |
Assuming that "textpad" means text file, you have a couple of options. For a small file like the one shown, the easiest solution would be to read
in the entire file as a string, and replace the commas with a comma + newline, as @TimBiegeleisen's answer shows.
For larger files, this may not be a good option due to memory constraints. In that case, and for the sake of generality, I like to iterate over the lines of a file. Here is a fairly simple generator that behaves like a normal file iterator, but also splits on commas:
from itertools import zip_longest, repeat
import re
def spliterator(file):
for line in file:
segments = re.split(r',s*', line)
ends = repeat(',n', len(segments) - 1)
for item in zip_longest(segments, ends, fillvalue=''):
yield ''.join(item)
It would be pretty simple to make this accept the split pattern as an argument, optionally keep the trailing spaces, and return the whole line with newline characters inserted.
Using the generator is simple, since it just wraps a normal file object or any other iterable of lines:
with open('textpad.txt') as file:
print(''.join(spliterator(file)))
Here is an IDEOne link with a demo.
To get the contents of the whole file as though read in by readlines
, just wrap in list
:
lines = list(spliterator(file))
To write back to an open output file, use writelines
directly:
output.writelines(spliterator(file))
Assuming that "textpad" means text file, you have a couple of options. For a small file like the one shown, the easiest solution would be to read
in the entire file as a string, and replace the commas with a comma + newline, as @TimBiegeleisen's answer shows.
For larger files, this may not be a good option due to memory constraints. In that case, and for the sake of generality, I like to iterate over the lines of a file. Here is a fairly simple generator that behaves like a normal file iterator, but also splits on commas:
from itertools import zip_longest, repeat
import re
def spliterator(file):
for line in file:
segments = re.split(r',s*', line)
ends = repeat(',n', len(segments) - 1)
for item in zip_longest(segments, ends, fillvalue=''):
yield ''.join(item)
It would be pretty simple to make this accept the split pattern as an argument, optionally keep the trailing spaces, and return the whole line with newline characters inserted.
Using the generator is simple, since it just wraps a normal file object or any other iterable of lines:
with open('textpad.txt') as file:
print(''.join(spliterator(file)))
Here is an IDEOne link with a demo.
To get the contents of the whole file as though read in by readlines
, just wrap in list
:
lines = list(spliterator(file))
To write back to an open output file, use writelines
directly:
output.writelines(spliterator(file))
edited Jan 2 at 6:47
answered Jan 2 at 4:50
Mad PhysicistMad Physicist
38k1674108
38k1674108
Apologies, i have just edited my required output..
– asimo
Jan 2 at 6:34
@Asimo. Please don't change your question after you've received valid answers. Instead, select an answer and ask another question if you have to.
– Mad Physicist
Jan 2 at 6:38
Let me revert back..Sorry for the hassle.. I have anways found a workaround to get the output in my desired format using your answer.. simply adding with open(r'H:Messengertest_Nov2.txt') as file: lines = ''.join(spliterator(file)) lines2 = lines.splitlines()
– asimo
Jan 2 at 6:39
@Asimo. The change you made is something you should be able to figure out in your own, or at least attempt, given the answers posted here.
– Mad Physicist
Jan 2 at 6:39
@asimo. Why not justlist(spliterator(file))
? No need for the extra hoops. Or you could just use the generator directly. I'm guessing you don't actually need the list.
– Mad Physicist
Jan 2 at 6:41
add a comment |
Apologies, i have just edited my required output..
– asimo
Jan 2 at 6:34
@Asimo. Please don't change your question after you've received valid answers. Instead, select an answer and ask another question if you have to.
– Mad Physicist
Jan 2 at 6:38
Let me revert back..Sorry for the hassle.. I have anways found a workaround to get the output in my desired format using your answer.. simply adding with open(r'H:Messengertest_Nov2.txt') as file: lines = ''.join(spliterator(file)) lines2 = lines.splitlines()
– asimo
Jan 2 at 6:39
@Asimo. The change you made is something you should be able to figure out in your own, or at least attempt, given the answers posted here.
– Mad Physicist
Jan 2 at 6:39
@asimo. Why not justlist(spliterator(file))
? No need for the extra hoops. Or you could just use the generator directly. I'm guessing you don't actually need the list.
– Mad Physicist
Jan 2 at 6:41
Apologies, i have just edited my required output..
– asimo
Jan 2 at 6:34
Apologies, i have just edited my required output..
– asimo
Jan 2 at 6:34
@Asimo. Please don't change your question after you've received valid answers. Instead, select an answer and ask another question if you have to.
– Mad Physicist
Jan 2 at 6:38
@Asimo. Please don't change your question after you've received valid answers. Instead, select an answer and ask another question if you have to.
– Mad Physicist
Jan 2 at 6:38
Let me revert back..Sorry for the hassle.. I have anways found a workaround to get the output in my desired format using your answer.. simply adding with open(r'H:Messengertest_Nov2.txt') as file: lines = ''.join(spliterator(file)) lines2 = lines.splitlines()
– asimo
Jan 2 at 6:39
Let me revert back..Sorry for the hassle.. I have anways found a workaround to get the output in my desired format using your answer.. simply adding with open(r'H:Messengertest_Nov2.txt') as file: lines = ''.join(spliterator(file)) lines2 = lines.splitlines()
– asimo
Jan 2 at 6:39
@Asimo. The change you made is something you should be able to figure out in your own, or at least attempt, given the answers posted here.
– Mad Physicist
Jan 2 at 6:39
@Asimo. The change you made is something you should be able to figure out in your own, or at least attempt, given the answers posted here.
– Mad Physicist
Jan 2 at 6:39
@asimo. Why not just
list(spliterator(file))
? No need for the extra hoops. Or you could just use the generator directly. I'm guessing you don't actually need the list.– Mad Physicist
Jan 2 at 6:41
@asimo. Why not just
list(spliterator(file))
? No need for the extra hoops. Or you could just use the generator directly. I'm guessing you don't actually need the list.– Mad Physicist
Jan 2 at 6:41
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001125%2fsplit-strip-a-set-of-lines-on-encountering-newline-or-comma%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Your expected output has all the spaces intact, but the title mentions stripping. Which one is it?
– Mad Physicist
Jan 2 at 4:29
Sorry, the spaces at the end of the lines can be trimmed..
– asimo
Jan 2 at 4:31