I have a program in which I read from a string that's formatted to have a specific look. I need the numbers which are separated by a comma (e.g. "A,B,D,R0,34,CDF"->"A","B","D","R0", "34", "CDF"). There are commas between letters that much is guaranteed I have tried to do (note: "variables" is a 2D char array, newInput is a string which is a method argumend, k and j are declared and defined as 0)
for(int i=0; i<=newInput.Length; i++){
while(Char.IsLetter(newInput[i])){
variables[k,j]=(char)newInput[i];
i++;
k++;
}
k=0;j++;
}
with multi-dimensional character arrays. Is there a way for this to be done with strings? Because char arrays conflict with many parts of the program where this method has already been implemented
Using split() If the string and separator are both empty strings, an empty array is returned. The following example defines a function that splits a string into an array of strings using separator .
As the name suggests, a Java String Split() method is used to decompose or split the invoking Java String into parts and return the Array. Each part or item of an Array is delimited by the delimiters(“”, “ ”, \\) or regular expression that we have passed. The return type of Split is an Array of type Strings.
Split is used to break a delimited string into substrings. You can use either a character array or a string array to specify zero or more delimiting characters or strings. If no delimiting characters are specified, the string is split at white-space characters.
Simple. Just use the Split
method:
var input = "A,B,D,R0,34,CDF";
var output = input.Split(','); // [ "A", "B", "D", "R0", "34", "CDF" ]
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