I'm getting pretty frustrated with this, and hope the community can help me out.
I have a string, an example would be "1_ks_Males", another example would be "12_ks_Females".
What I need to do is write a method that extract's each value. So from the first example I'd want something like this:
1 ks Males
In separate variables.
I'm sure I'm just being incredibly thick, but I just can't get it!
The strtok() function is the traditional C library routine used to slice up a string.
You call the Substring(Int32) method to extract a substring from a string that begins at a specified character position and ends at the end of the string. The starting character position is a zero-based; in other words, the first character in the string is at index 0, not index 1.
The strtok function is a handy way to read and interpret data from strings. Use it in your next project to simplify how you read data into your program. By Jim Hall (Correspondent) April 30, 2022 | 0 Comments | 4 min read.
strcpy() is a standard library function in C/C++ and is used to copy one string to another. In C it is present in string. h header file and in C++ it is present in cstring header file. Syntax: char* strcpy(char* dest, const char* src);
Simply use string.Split('_')
. With your input strings it will return a string
array with three elements.
You can use Split
function for String
. Something like this
var split = "1_ks_Males".Split('_');
var first = split[0];
var second = split[1];
var third = split[2];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With