ShadowRanger24 50 Posted October 27, 2016 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
gc8 970 Posted October 27, 2016 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
Tajin 348 Posted October 27, 2016 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
ShadowRanger24 50 Posted October 27, 2016 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
killzone_kid 1326 Posted October 27, 2016 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