I'm writing some axlSkill that reads the variants.lst file. The statement xx = infile("variants.lst") opens the file for reading.The statement gets(s xx) gets the first line written to a string object s.Now I'm trying to use a getchar call to look at each character of the string and then decide what to do with the line. Specifically I'm looking for strings that start with "(" (for example).I try getchar(s 1) == "(" hoping for a return value of t. But even though the first character of string s is ( the getchar call returns nil.I'm guessing there is an easy way to parse a string and I haven't found it.Help?
getchar returns a character not a string so do getchar(s 1) == '\(also since a paren is special in Skill it needs to be escaped by a backslash, to match a 'd' all you would need is a 'd
Some other options:1) use substring instead of getchar. substring(s 1 1) == "("2) convert the getchar result to a string get_string(getchar(s 1)) == "("
Thanks! Another - even more general - question.I've got a major brain freeze going here.I'm using a while to read a text file (the variants.lst file). In this example I look at the first character of each line and see if it is an open paren. xx = infile("variants.lst") count = 0 while(xx gets(s xx) lineno = count++ if(substring(s 1 1)=="(" then printf("Line #%d starts with a \"(\"\n" lineno) else printf("Line #%d doesn't start with a \"(\"\n" lineno) ); end if ); end whileProblem is that after the last line of the infile is read I get:E- *Error* substring: argument #1 should be either a string or a symbol (type template = "Sx") - nilThe last gets statement has returned a string that is nil.If I put in an if loop if(s != nil after the gets statement the while loop goes forever. How do I evaluate the result of the gets statement before trying to use it?
See if this works:if( xx = infile("variants.lst") ; make sure we can open the filethencount = 0while( gets(s xx)lineno = count++if(substring(s 1 1)=="("thenprintf("Line #%d starts with a \"(\"\n" lineno)elseprintf("Line #%d doesn't start with a \"(\"\n" lineno)); end if); end whileclose(xx); close out the input port); end if