How do I block the Space key?

Get help using Construct 2

Post » Sun Jun 22, 2014 4:03 pm

Hi again :D

i have this events to set a minimum of 3 characters length and a maximum of 15
Image

the thing is that i dont want to have Spaces, is there a way to block it? even if someone Paste a string with Spaces on it? or to not count the Blank Spaces as a char?

what im trying to do is to verify the textbox has more than 3 characters but i dont want to count the blank spaces...

any ideas?


thanks again
B
13
S
2
G
1
Posts: 28
Reputation: 960

Post » Sun Jun 22, 2014 4:18 pm

You can use the regex system expressions.

Remove all spaces from string ("\s" matches any whitespace, "g" = global, replaces all occurences):
Code: Select all
RegexReplace(TextBox.Text, "\s", "g", "")


Count number of spaces:
Code: Select all
RegexMatchCount(TextBox.Text, "\s", "g")
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,630

Post » Wed Jun 24, 2015 6:23 pm

ramones wrote:Remove all spaces from string ("\s" matches any whitespace, "g" = global, replaces all occurences):


@ramones where did you find a list of the flags? I can't find it anywhere. The doc on this is ridiculously thin..

do you know how to concat the flags together? if I wanted to remove whitespaces and "-" dashes? or do I have to do it as separate Actions? I actually want to remove all non alphas... is there a flag for that?
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Wed Jun 24, 2015 7:13 pm

jobel wrote:
ramones wrote:Remove all spaces from string ("\s" matches any whitespace, "g" = global, replaces all occurences):


@ramones where did you find a list of the flags? I can't find it anywhere. The doc on this is ridiculously thin..

do you know how to concat the flags together? if I wanted to remove whitespaces and "-" dashes? or do I have to do it as separate Actions? I actually want to remove all non alphas... is there a flag for that?


What?
Google "regex" will give you more results than you ever can read...
http://eloquentjavascript.net/09_regexp.html
Sorry for my bad english, but I really do my best! And use and check with Google Translator.
B
10
S
4
G
1
Posts: 158
Reputation: 1,303

Post » Wed Jun 24, 2015 7:43 pm

I'm sure he meant in C2 / the manual. But yeah regular expressions can be used in most programming languages and there are lots of guides out there.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,630

Post » Wed Jun 24, 2015 7:51 pm

RegExr is an online tool to learn, build, & test Regular Expressions(RegEx / RegExp).
Image
B
63
S
23
G
7
Posts: 1,480
Reputation: 10,796

Post » Wed Jun 24, 2015 8:54 pm

For this you don't even need regex necessarily.
replace(srctxt, " ", "")

and if you wanna find out the length without spaces:
len(replace(srctxt, " ", ""))

Of course regex has it's advantage. It can also catch other whitespace characters in one go and replace them for you etc, like Ramones showed.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Thu Jun 25, 2015 12:20 am

deathangel1479 wrote:What?
Google "regex" will give you more results than you ever can read...
http://eloquentjavascript.net/09_regexp.html


oh javascript.. that was not clear. I'm a C/C++ person I haven't done much js. Still there should be a link in the doc to something like this and not assume users know the flags or know it's js.
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Thu Jun 25, 2015 12:24 am

korbaach wrote:RegExr is an online tool to learn, build, & test Regular Expressions(RegEx / RegExp).

oh it's not js? it is it's own thing? well it's a standard I know nothing about, so good to know!
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Thu Jun 25, 2015 12:26 am

okay so these..

\d Any digit character
\w An alphanumeric character (“word character”)
\s Any whitespace character (space, tab, newline, and similar)
\D A character that is not a digit
\W A nonalphanumeric character
\S A nonwhitespace character
. Any character except for newline
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, Yahoo [Bot] and 5 guests