Re: sequence and strings (newbie help wanted)
- Posted by Kat <gertie at PELL.NET> Mar 15, 2001
- 459 views
On 14 Mar 2001, at 21:40, jc at cknet.net wrote: > > > Hello, > Just begining with Euphoria, this is my first script. Trying to get the > command_line() and parse through it. Thought I would start by throwing the > contents of command_line() on the screen: > > include get.e > object cmd > cmd Page break? ommand_line() > puts(1, cmd) > > vwait > -- putting the wait_key() in just so my screen remain up > > I get an error message saying that I have a sequence in a character string. > In my ex.err I find: > > cmd > 65'A',92'\',66'B',73'I',78'N',92'\',101'e',120'x',119'w',46'.',101'e', > 120'x',101'e'},{67'C',58':',92'\',69'E',85'U',80'P',72'H',79'O',82'R', > 73'I',65'A',92'\',66'B',73'I',78'N',92'\',102'f',105'i',114'r',115's', > 116't',46'.',101'e',120'x',119'w'}} That's how Eu stored the command line, alright. The debug printout shows the bytes, followed by printable chars. Maybe what you wanted to use was gets() and puts()? > Is this how Euphoria internally stores a string/sequence. Obviously I don't > understand something fundamental here with strings and sequences. Strictly speaking, there are no strings in Eu, but we can use sequences as strings. A sequence is a sequence of bytes, for any purpose. They can even be nested inside each other. Like this: seq = {this is {sequence #2} sequence #1} so: seq[1] = 't' seq[9] = "sequence #2" seq[9][2] = 'e' There are a number of string handling librarys in the Eu archives to make sequences more string-like. There are prolly 4 or 5 of them, from basics, to very flexable strings, to calling words tokens, to regexp stuff that is beyond me. Just hold onto your hat when you get to print(), printf(), sprint(), sprintf(), print.e, printseq(), displayseq(), etc, etc... > Also, looking for a word() function, but not finding one in Euphoria. Is > there a built in function that will parse through command_line() returning > the Nth word ? Problem with sequences (for newcomers) is their flexability. While you can put words into a sequence, you'd need a string lib to get them back out, since the string lib knows about whitespace, periods, commas, etc.. Unless you stored a string as: str= {"word1","word2","word3"} in which case, str[2] = "word2" the command_line is: cmd={"path","path","the first optional parm","another optional parm"} so cmd[1] = the full path of the exw.exe cmd[2] = the path and name of your program cmd[3..length(cmd)] = the various parms you want your program to have. The closest thing to word() in strings that i know of is the lib i submitted at: http://www.rapideuphoria.com/strtok.zip since i call words in natural language "tokens" of the language, items of meaning, if you know what i mean. You'll find a lot of token functions in there. /me thanks everyone who contributed code to it again. Look at: for more. I don't see strings.e by Normand Blais there tho, and it isn't found in the rds archive search either,,, so get string0_9.e from inside http://www.rapideuphoria.com/mirc.zip and you'll be all set. The functions removed to make string0_9.e from string.e is in strtok.zip, in different code though. Hope this helps, Kat