Jump to content
Sign in to follow this  
ShadowRanger24

Select Character From String

Recommended Posts

So I'm trying to figure out a way to select a character from a string. According to the official wiki, the 'select' command can do this. But it does not work as said. Test code:

 




_string = "This is a test"; 
hint format ["%1", _string select [0, count _string]];



 

Using this code outputs the whole string, and not just the selected character as it should. Any ideas? Thanks in advance.

Share this post


Link to post
Share on other sites

 

So I'm trying to figure out a way to select a character from a string. According to the official wiki, the 'select' command can do this. But it does not work as said. Test code:
 

_string = "This is a test"; 
hint format ["%1", _string select [0, count _string]];

 
Using this code outputs the whole string, and not just the selected character as it should. Any ideas? Thanks in advance.

 

 

change the "count _string" to 1

Share this post


Link to post
Share on other sites

 

outputs the whole string, and not just the selected character as it should. Any ideas?

 

 

The command does exactly what it should. Maybe you just misunderstood the syntax :)

string select [start, length]

In your code you tell it to start from position 0 (the beginning) and return a string with the length (count _string). So yes, you're actually telling it to return the whole string from beginning to end.

 

 

 

 

just the selected character

"selected" where ?

_string = "This is a test"; 
hint format ["%1", _string select [5, 2]];
// returns "is"

Share this post


Link to post
Share on other sites

 

The command does exactly what it should. Maybe you just misunderstood the syntax :)

string select [start, length]

In your code you tell it to start from position 0 (the beginning) and return a string with the length (count _string). So yes, you're actually telling it to return the whole string from beginning to end.

 

 

 

"selected" where ?

_string = "This is a test"; 
hint format ["%1", _string select [5, 2]];
// returns "is"

Ah I see, oops. Works now. Thanks! :)

Share this post


Link to post
Share on other sites

According to the official wiki, the 'select' command can do this. But it does not work as said.

 

 

 

 

length (optional): Number - Number of the string characters to select. If "length" is omitted, selection will be made from "start" to the end of the string.

You passed the number of characters in the string, so it works exactly as said

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×