Working with number strings

0 favourites
  • 5 posts
From the Asset Store
This collection of music is the beautiful performance of rather small strings ensemble (8 first violins, 6 second violin
  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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. :)

  • Thanks <img src="smileys/smiley1.gif" border="0" align="middle" />

    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)?

  • 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).

  • 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).

    Indeed, very good point Ashley!

    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)?

    Yes, the int expression converts to an integer value.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)