How do I access characters in a string

Get help using Construct 2

Post » Wed Sep 02, 2015 10:57 am

Hi,

I have a String like this "Hello World"
How do I get specific characters of this string like the second letter? Is this even possible?
B
4
Posts: 4
Reputation: 208

Post » Wed Sep 02, 2015 11:07 am

Mijdax wrote:Hi,

I have a String like this "Hello World"
How do I get specific characters of this string like the second letter? Is this even possible?


There are numerous System expressions that deal with text in the Manual.

Some that may be of use to you are:


find(src, text)
Find the first index within src that text occurs, else returns -1.

left(text, count)
Return the first count characters of text.

len(text)
Return the number of characters in text.

mid(text, index, count)
Return the count characters starting from index in text.

right(text, count)
Return the last count characters of text.


So for instance, if I had a string such as "My World" stored in a variable called 'mytxt', then

mid(mytext, 4,1) would just show the letter 'o'.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
134
S
30
G
84
Posts: 5,379
Reputation: 58,440

Post » Wed Sep 02, 2015 9:46 pm

Thank you very much! That was exactly what I was searching for <3
B
4
Posts: 4
Reputation: 208

Post » Fri May 26, 2017 12:01 pm

Hi. Thanks for the info. If i want to extract the last 3 characters of a string at once, how i do this?
Making right(text, 3) right(text, 2) right(text, 1), making right(text, 3)? or other thing?
If i want to extract (counting from right to left) character 3 and 4 at once?
B
8
Posts: 5
Reputation: 312


Return to How do I....?

Who is online

Users browsing this forum: DharmaOne, namaewayukidesu and 20 guests