How do I remove some lines of a text?

Get help using Construct 2

Post » Thu Jan 26, 2017 3:54 pm

Hey gus! I have an issue.. Is there any fast solution to remove lines of a text?

Example:
Code: Select all
Hello there!
This is a simple test.
I need to remove this character and
delete this line,
and this line..
Without remove this!


What i need, is to find the "character" word, and press delete button. After this to remove the lines above and below.. So to have this result:
Code: Select all
This is a simple test.
Without remove this!


Can i? Thank you!!! ; -)
Last edited by odiusfly on Fri Jan 27, 2017 9:39 am, edited 2 times in total.
B
52
S
32
G
13
Posts: 241
Reputation: 11,831

Post » Thu Jan 26, 2017 5:42 pm

I find this: RegexReplace(Text.Text, ".*character.*\r?\n", "m", "")..
.. But the result is to remove 1 line (the line with the "character" word) only. :roll:

Can't find any regex to remove 1-2 lines above and 1-2 lines below for example.
B
52
S
32
G
13
Posts: 241
Reputation: 11,831

Post » Thu Jan 26, 2017 9:26 pm

You can try breaking your text up into individual lines first before working with them using tokenat() and the "newline" expression as your token. Push each line separately into a temporary array and then do whatever you want with them.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Thu Jan 26, 2017 9:33 pm

Thank you for your reply.. but if i need to use a ready text from a file (ajax) for example, and don't want to use array? Can I?
I think regex is the faster answer (or someone to find better idea of course), but unfortunately can't find the code which can remove above and below lines.
B
52
S
32
G
13
Posts: 241
Reputation: 11,831

Post » Fri Jan 27, 2017 12:40 am

Try [\r\n] to match a line break, not sure if it will work though.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Fri Jan 27, 2017 7:39 am

No working.
B
52
S
32
G
13
Posts: 241
Reputation: 11,831

Post » Fri Jan 27, 2017 9:07 am

The issue here is that you speak of formatting in lines.
But how does that formatting actually happens ? You speak of a source text coming from AJAX, can you provide an actual example of text ?
Your example in code in your first post is confusing as it is presented :

Code: Select all
Hello there!
This is a simple test.
I need to remove this character and
delete this line,
and this line..


Code: Select all
Hello there!
Without remove this!



Shouldn't actually the result be, in regards to your original text and what you have described (above line and below line):
Code: Select all
Hello there!
and this line..


?
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
289
S
112
G
94
Posts: 7,333
Reputation: 69,293

Post » Fri Jan 27, 2017 9:35 am

Choice 1: Imagine to write a big text with breaklines in a textbox inside construct 2.
Choice 2: Now, the same text you can write in a .txt file on windows right? <-- Here is coming ajax plugin in case you want to insert in construct 2.

Now you have a button.. Click and search for a "character, number whatever" inside your text.
So this code, a regex code maybe to remove all the line of the "character, number whatever" and 1-2 (maybe 5-10) lines above and 1-2 (maybe 5-10) lines below.

Hope you understand now! ; -)

@Kyatric
Sorry, i edit my code example above.. You can see now!
B
52
S
32
G
13
Posts: 241
Reputation: 11,831


Return to How do I....?

Who is online

Users browsing this forum: TELLES0808 and 7 guests