05-28-2013 12:19 PM
Hello,
I am trying to use match pattern to read numbers and strings from a file. I can't seem to figure out how to allow the function to read the strings. For example, if the file contains the following:
1.1 2.1 3.1 Cat DOG
I would think that [.]?[0-9]+[.]?[0-9]*[Cat][DOG] would do the trick. Any pointers?
Thanks,
Micah
05-28-2013 01:05 PM
Match Pattern isn't as powerful as Match Regular Expression, and some of what you're trying to do requires that power.
I changed your regexp a little by escaping the decimal points, grouping/repeating the number search and making literals out of "Cat DOG". We'd need a better description, or a more representative sample, of your expected data to do more.
([\.]?[0-9]+[\.]?[0-9]* )*[\w\s]*
05-28-2013 01:15 PM
05-28-2013 02:58 PM
When I use this syntax for the regular expression input, my code only picks out the string and does not read the numbes. To expand a bit on my projet, the file I am reading in has 12 columns but I only care about the 1st, 9th, and 11th columns. The problem I am having is columns 10 and 12 are the strings (indicating fault degredation modes in a test bed). I simply want my code to read in all the columns and then I'll process the data that I need.
Thanks,
Micah
05-28-2013 03:01 PM
@apok wrote:
This is not a solution, %s will match any string not only Cat and DOG and if the input string do not match the format string it will generate an error.
Ben64
05-28-2013 07:11 PM - edited 05-28-2013 07:14 PM
@Micah59 wrote:
[...] the file I am reading in has 12 columns but I only care about the 1st, 9th, and 11th columns. The problem I am having is columns 10 and 12 are the strings (indicating fault degredation modes in a test bed). I simply want my code to read in all the columns and then I'll process the data that I need.
Thanks,
Micah
If the data is always deliminated by spaces, you can use Spreadsheet String to Array:
If you need to do anything with the fault strings, you can replace the Double constant (in the array constant) with a String and convert whichever numbers you need from the resulting array of Strings.