# Working with number strings

Get help using Construct 2

### » Mon Nov 12, 2012 9:21 am

I want to take the first four digits from a number string AND delete them from that string.

For example, from "100323444577" take "1003" and leave the string as "23444577".

The long string doesn't need to be a value, it can be a text string. But then I'd like to take that 4 digit value and convert it to 4 single digit values.

How would I do that?
B
7
S
2
G
2
Posts: 25
Reputation: 1,910

### » Mon Nov 12, 2012 3:10 pm

You need to learn about system expressions.

The expression left(text,count) will return the first characters of a string (as specified in "count").

To remove characters you can use the replace(text,find,rep) expression. With the example you provided it would look like:

replace("100332444577",left("100332444577",4),"")

Remember that these expressions need a string to work with. So in case you want to manipulate an integer variable, you'll need to add the str expression to convert it to a string.

If you had a string with the length of 4, you could pick any part of it with yet another expression: mid(text, index, count)

As you can see expressions are pretty vital, so do read up on it. :)PixelRebirth2012-11-12 15:11:36
B
25
S
6
G
11
Posts: 1,049
Reputation: 8,119

### » Mon Nov 12, 2012 3:35 pm

Thanks

And how would I do the opposite? Take a string and make it into an integer to replace the value in a variable? With int(x)?Angel2012-11-12 15:37:46
B
7
S
2
G
2
Posts: 25
Reputation: 1,910

### » Mon Nov 12, 2012 3:36 pm

I wouldn't use replace()! replace("100310031003", "1003", "") will result in an empty string, when you just want to remove the first four characters. I'd use right(str, len(str) - 4).
Scirra Founder
B
408
S
242
G
92
Posts: 24,888
Reputation: 198,582

### » Mon Nov 12, 2012 3:41 pm

[QUOTE=Ashley] I wouldn't use replace()! replace("100310031003", "1003", "") will result in an empty string, when you just want to remove the first four characters. I'd use right(str, len(str) - 4).[/QUOTE]

Indeed, very good point Ashley!

[QUOTE=Angel]And how would I do the opposite? Take a string and make it into an integer to replace the value in a variable? With int(x)?[/QUOTE]

Yes, the int expression converts to an integer value.
B
25
S
6
G
11
Posts: 1,049
Reputation: 8,119