Testing for numbers only.
in
Programming Questions
•
1 years ago
Well, i'm reading a Tab delimited document using loadStrings(); I need to find lines starting with numbers.
So i wrote this code. It works, but i got a feeling that might be a better way... Are there?
Note that this is a test code i wrote apart of the main sketch to test the idea. So i made two sample Strings to test. I posted this to keep things small and aesy to understand.
Thanks
Vicente
- String numbers = "0 1 2 3 4 5 6 7 8 9";
- String[] number;
- String startLetter = "FINAL CUT 000";
- String startNumb = "893 casa da voo";
- void setup()
- {
- number = split(numbers," ");
- }
- void draw() {
- for (int i=0;i< number.length;i++) {
- if(startLetter.startsWith(number[i])) {
- println("letter is not number against number "+i);
- }
- else {
- println("tested false from startLetter against number "+i);
- }
- if(startNumb.startsWith(number[i])) {
- println("A number is always a number and this number is number "+i);
- }
- else {
- println("tested false from startNumber against number "+i);
- }
- }
- noLoop();
- }
1