How do I know the number of new lines in a textbox ?

Get help using Construct 2

Post » Fri May 01, 2015 9:56 pm

Hi !

I have a textbox with some text and some new lines.

Is it possible to know how many lines are currently used ?

edit : how, a regex on \n, simple as this.

edit : no, it wasn't.
The regex works if the user has pressed enter to create a new line, but not if a new line is created automatically.

Any idea ?
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Sat May 02, 2015 7:47 am

What about something like: tokencount(TextBox.Text,newline)
If your vision so exceeds your ability, then look to something closer.
Moderator
B
137
S
31
G
87
Posts: 5,556
Reputation: 60,456

Post » Sat May 02, 2015 10:09 am

RegexMatchCount(TextBox.Text, "(\r\n|\r|\n)", "g")=tokencount(TextBox.Text,newline)

...because needs separator...if you set TextBox as TextArea and when you start typing
just press "a" and hold down..you dont have separator.....you just wrap text....

..........I think :?

you also need to to set Max.Characters per line ...and count characters in line...
On text change add to Var.Characters... 1
Var.Characters= Max.Characters .....set text ..to text&newline....set Var.Ch=0
..also need to set Var.Ch=0 when Var.Lines change if you press Enter...


EDIT:
@Coin-coin le Canapin
something like this..
capx> http://s000.tinyupload.com/index.php?fi ... 1575242769
Last edited by korbaach on Sat May 02, 2015 11:57 am, edited 1 time in total.
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Sat May 02, 2015 11:15 am

Would be easier with monospace fonts. :D

korbaach, your example doesn't work, it doesn't add a new line when a new line is automatically created.

By the way it seems there is no simple solution as such a new line triggers no event.

I guess the simplest solution would be this one : https://stackoverflow.com/questions/164 ... a-textarea
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Sat May 02, 2015 11:28 am

Coin-coin le Canapin wrote:korbaach, your example doesn't work, it doesn't add a new line when a new line is automatically created.


what's wrong with this?..............I'm confused :?
Image
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Sat May 02, 2015 12:21 pm

It doesn't work if you put some spaces :)
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Sat May 02, 2015 12:37 pm

Ok...Now I'm even more confused :lol:

Image
This works exactly the way I want...counts all lines..even empty lines....

Perhaps I did not understand exactly what you want :?
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Sat May 02, 2015 12:39 pm

Ah ! Okay ; I mean, it doesn't work when copy pasting. :D
But don't bother to fix this, you did an amazing job, thank you :)
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Sat May 02, 2015 12:46 pm

Thanks and you're welcome @Coin-coin le Canapin ! :D
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 21 guests