How do I join specific long lines that should be a single line (was: "Help.. how to...")
-
Hi, first of all apologies for my English…
I got a document in notepad++
The problem is that it is a document with 325 questions and I want to import them to Moodle in the Aiken format…
Some of the questions have, the questions and some answers in MORE than ONE line… and I can’t import them because of that, so…
Is there a way to “select” those more than one lines in the questions or answers and convert them in a single line question or answer?
Example
Question: 1- Blab bla bla bla blalbla?: A) lksjdfljksldfkj lkjsdflkjsdf B ) irfiifiif C) iasiaflikfasdlkjf D) ioririf
As you can see question 1 has two lines and answer A has two lines… how can i “find” all of those situations in notepad++ and replace them for a single line? Or at least the most easy way…
What I want:
1- Bla bla bla bla bla?: A) ajsdkdjaskjadks B) klasddasklj C) ajklsddasjkldsa D) sjkldfoads
Thanks.
—
1. moderator added code markdown around text; please don’t forget to use the
</>
button to mark example text as “code” so that characters don’t get changed by the forum
2. moderator updated title of post per discussion below -
@Un-Known said in Help.. how to...:
Is there a way to “select” those more than one lines in the questions or answers and convert them in a single line question or answer?
Yes, and it uses regular expressions. In your example of data before the changes are made you show answer B as having a space between the B and the ). I’m assuming that was a mistake and my solution assumes the same.
So using the Replace function and with search mode set to “regular expression” we have:
Find What:\R(?!=\d+-|[ABCD]\))
Leave the Replace With field empty, so this will delete the end of line where necessary.Test this by using the Replace button only. Once you are happy with the result you could use the “Replace All” button which will complete the changes in the document. Make sure you work with a copy of the document, that’s always a good idea when deleting/altering stuff, at least for the first time.
Terry
-
Leave the Replace With field empty, so this will delete the end of line where necessary.
Do you want to leave it empty, or replace it with a space?
I think yours was too aggressive, even with a space:
BEFORE
Question: 1- This question originally spread across multiple lines?: A) This answer also started as two lines B) To Be or Not To Be C) I am not right D) Don't even think of guessing D ... 9- Short Question A) Short Answer B) Be Short C) See, I am short D) Done 13- Another question originally spread across multiple lines?: A) Apples B) Not the answer, but spread across multiple lines C) Cats! D) Dogs. Run away, run away!
AFTER (without space)
Question:1- This question originally spreadacross multiple lines?: A) This answer also startedas two lines B) To Be or Not To Be C) I am not right D) Don't even think of guessing D...9- Short Question A) Short Answer B) Be Short C) See, I am short D) Done13- Another question originally spreadacross multiple lines?: A) Apples B) Not the answer,but spread across multiple lines C) Cats! D) Dogs. Run away,run away!
AFTER (with space):
Question: 1- This question originally spread across multiple lines?: A) This answer also started as two lines B) To Be or Not To Be C) I am not right D) Don't even think of guessing D ... 9- Short Question A) Short Answer B) Be Short C) See, I am short D) Done 13- Another question originally spread across multiple lines?: A) Apples B) Not the answer, but spread across multiple lines C) Cats! D) Dogs. Run away, run away!
I was going to suggest something like
^(\d+-|[A-Z]\))(.*?)\R((?!\d+-|[A-Z]\)|\R).*$)
replace with$1$2 $3
, but you beat me again, and I think a hopefully-small tweak to yours would bring it in to working, without getting as complicated as mine.When asking questions, it’s best to have a meaningful title (even if you have to translate it from your native language). “Help… how to…” doesn’t tell the person looking at the list of posts anything about your post. On the other hand, “How do I join specific long lines that should be a single line” would tell the reader instantly what you are trying to do.
Also, given this is a search-and-replace question, here are some useful references for helping you ask such questions, which helps us give better answers.
-
@PeterJones said in Help.. how to...:
How do I join specific long lines that should be a single line
A moderator should change this thread’s title to exactly that. :-)
-
@PeterJones said in How do I join specific long lines that should be a single line (was: "Help.. how to..."):
Do you want to leave it empty, or replace it with a space?
I think yours was too aggressive, even with a space:
Very possibly. I was looking at the examples provided and of course it’s just made up stuff, gibberish. The after examples don’t match up either with
blabla
becomingbla bla
.So I assumed there will likely be a bit of to and fro before OP becomes happy. My solution at least will let them know it’s possible and they need to sort out proper examples!
Cheers
TerryPS next time provide your solution before using moderator abilities to adjust examples and you might beat me ;-))
-
@Terry-R ,
So I assumed there will likely be a bit of to and fro before OP becomes happy. My solution at least will let them know it’s possible and they need to sort out proper examples!
Good point. But since I wrote what follows, I’ll at least present it as the best starting point for the user
@PeterJones said in Help.. how to...:
I think a hopefully-small tweak to yours would bring it in to working, without getting as complicated as mine.
FIND =
(?<![\r\n])\R(?!=\d+-|[ABCD]\)|\R)
– adds a check to make sure that the previous line wasn’t also a newline and that the next line after the matched line isn’t a newline (thus allowing spaces between questions and answers)From my data above, this slight tweak to @Terry-R’s regex gives
NEXT TRY:Question: 1- This question originally spread across multiple lines?: A) This answer also started as two lines B) To Be or Not To Be C) I am not right D) Don't even think of guessing D ... 9- Short Question A) Short Answer B) Be Short C) See, I am short D) Done 13- Another question originally spread across multiple lines?: A) Apples B) Not the answer, but spread across multiple lines C) Cats! D) Dogs. Run away, run away!
… which I think is a reasonable merging of the data. And if there are some questions/answers spread over three or more lines, just run the regex more than once, until nothing changes.
-
First of all sorry for all the mistakes… reading the answers it seems the leaving spaces where there where supposed not to be and not using words, made things difficult.
Sorry… As i said English is not my mother tongue.
Example 1
1- What’s your
name?:A) Juan
B) Pedro de
la Fuente Rodriguez
C) Oscar
D) AlfredoWhat I want:
1- What’s your name?:
A) Juan
B) Pedro de la Fuente Rodriguez
C) Oscar
D) AlfredoSorry again, I supposed that you will guess that my mistakes where from just not being meticulous while writing… my bad.
I assume Terry’s answers is the correct one, thanks. I will try that.
-
@Un-Known said in How do I join specific long lines that should be a single line (was: "Help.. how to..."):
I assume Terry’s answers is the correct one, thanks. I will try that.
We don’t want you to assume. Try both and see what each does to your data, make sure you work on a copy of the document! Because you didn’t give us real data (a common issue we have when trying to help) it’s often a guessing game and will often take several posts both by yourself and the solution provider to get one that works for you.
Terry
-
As you can see the problem I have using Terry’s solution is that questions and the correct answer are in the same line.
I will try to post this better. I did it bad. Sorry.
Example:
1- What’s your
name?:A) Juan
B) Pedro de
la Fuente Rodriguez
C) Oscar
D) Alfredo
ANSWER: DWhat I want:
1- What’s your name?:
A) Juan
B) Pedro de la Fuente Rodriguez
C) Oscar
D) Alfredo
ANSWER: DSorry I omitid things like the field ANSWER because when i was talking about Moodle in the Aiken format I supposed people would know beforehand… Really sorry for not explaining things in the correct way. Really, sorry.
-
Terry
Really sorry. I know now that i did it bad.
-
@Un-Known said in How do I join specific long lines that should be a single line (was: "Help.. how to..."):
As you can see the problem I have using Terry’s solution is that questions and the correct answer are in the same line.
That’s what I tried to tell you in my follow-on posts.
But now that you’ve also told us that a line starting with
ANSWER
is also in the data, my previous suggestion will need to be tweaked.Please try this suggestion:
FIND WHAT =(?<![\r\n])\R(?!=\d+-|[ABCD]\)|ANSWER|\R)
REPLACE WITH =\x20
(or you could type a space character in the REPLACE WITH box).I believe that will work for you. (At least, it does with your most recent data)
-
Peter jones
THANK YOU SO MUCH!!! that worked!