Getting a single char out of a string variable
Monkey Forums/Monkey Programming/Getting a single char out of a string variable
| ||
Hi I have looked through the language reference types section and I still dont quite understand it. Im trying to take a single letter at a set position out of a string variable. I will not know what the string contains before hand e.g. SomeString = "ABCD" NewString = (Second Letter of) SomeString The result of Print NewString should be "B" Has something incredibly simple just gone right over my head? Thanks in advance |
| ||
Strict Function Main:Int() Local someString:String = "ABCD" Local newString:String newString = someString[1..2] Print(newString) Return 0 End |
| ||
Here's one way to do it, though it's not pretty!Function Main () Local test:String = "ABCD" Print String.FromChar (test [1]) End Have a look at Language Reference -> Types -> The String type. [EDIT: Sorry, you did.] |
| ||
DruggedBunny, How did you insert your code (black background, green text, and formatted)? |
| ||
Oh god it was so simple thank you very much, I had read the language reference but it just confused me even more |
| ||
@DrT: use (code)Whatever(/code) but with square brackets. Use (codebox) for larger code, as it appears in a scrollable box. |
| ||
DruggedBunny, Thanks for your help. I created a separate topic How to post code on this forum? and got help there also. Thanks again. |