How do I get a specific **string** among the others

Get help using Construct 2

Post » Tue Dec 30, 2014 7:17 am

Is it possible to get a specific letter or number in a string type value?

Example:

Retrieve LayoutName (Which is 1ABCDx2) and get x2, or AB, or 1, etc.

It's easy for numbers but for string I don't even know if it's possible.
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Tue Dec 30, 2014 7:39 am

This page is your very best friend (and mine too - any time a question about manipulating some values pops up there's a good chance the answer is there): https://www.scirra.com/manual/126/system-expressions
B
19
S
6
G
6
Posts: 1,101
Reputation: 5,646

Post » Tue Dec 30, 2014 3:06 pm

If you wanna check for that string in the name you can use:

find(LayoutName, string)

ex: find("1ABCDx2", "x2") would return 5.

If you wanna get the string from the name you can use one of the expressions below:

left(LayoutName, count)
right(LayoutName, count)
mid(LayoutName, index, count)

ex:
left("1ABCDx2", 1) would return "1".
right("1ABCDx2", 2) would return "x2".
mid("1ABCDx2", 1, 2) would return "AB".

And you could even use both together:

mid("1ABCDx2", find("1ABCDx2", "A"), 2) would return "AB".
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
16
S
4
G
1
Posts: 408
Reputation: 2,297

Post » Tue Dec 30, 2014 4:23 pm

brunopalermo wrote:If you wanna check for that string in the name you can use:

find(LayoutName, string)

ex: find("1ABCDx2", "x2") would return 5.

If you wanna get the string from the name you can use one of the expressions below:

left(LayoutName, count)
right(LayoutName, count)
mid(LayoutName, index, count)

ex:
left("1ABCDx2", 1) would return "1".
right("1ABCDx2", 2) would return "x2".
mid("1ABCDx2", 1, 2) would return "AB".

And you could even use both together:

mid("1ABCDx2", find("1ABCDx2", "A"), 2) would return "AB".


Thank you, brunopalermo. :D
B
56
S
21
G
3
Posts: 602
Reputation: 6,612


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 17 guests