Re: New User
- Posted by Ray Tomes <rtomes at ihug.co.nz> Jun 25, 2003
- 747 views
Derek Parnell wrote: > A string manipulation library is a great idea. It can help you learn lots > about Euphoria's capabilites fairly quickly. In fact, this type of library > is almost a rite of passage for new Eu coders. Please don't hestate to ask > questions or look at similar attempts from the RDS Archives. Yes, welcome Peter. I am rather new here too. I had just commented before you arrived how easy it is to manipulate strings in Euphoria, even easier than in BASIC. Someone pointed me at the find command as their "friend", and indeed it is. An example. I am writing a system that has prototype letters with tags of the form <XXX> (where XXX is three letters) that represent various things like names, addresses, dates etc and that must be replaced by some text that has the particular value of that variable for the particular person that the letter is being sent to. To make matters more complicated, I don't even know what the full list of tags is (and don't want to thank you very much as there are about a hundred of them and they get extended) but my person file has matched pairs of tag and value. So I read in a person's data and store in a couple of sequences as "tag" and "value" (where value[1] goes with tag[1] etc.). So I don't have any variable names such as "name", "address" and so on as the variable names are all stored in "tag" and the values of the variables in "value" in the matching position. This makes my program much smaller and it works when new variables are added without any changes being made. One function that I obviously want is to get into "thisvalue" the matching value of a tag whose value I have in "thistag" so all I need to code is: thisvalue=value[find(thistag,tag)] No loops, no searching. I suppose I should have an error test for not found. Next I want to take my letter and replace all tags by their values. Hey, I do need a string function for this and I don't see it anywhere as yet. It is a simple replace command something like: resultstring=replace(findstring,replacestring,originalstring) well, let me see if I can write this here and now without any testing... function replace (structure findstring, structure replacestring, structure originalstring) atom ix ix=find (findstring, originalstring) return originalstring[1..ix-1] & replacestring & originalstring[ix+length(findstring)..length(originalstring)] end function again I haven't done any check to see if it exists. But you can see how string functions in Euphoria almost write themselves - particularly when you know how useful find is. Another string function that I want is for the same program. I want to output some text in a text box with automatic wrap at a point NOT the same as the width of the text field and then put some more text to begin at the point where the wrapping was occurring and also to wrap but now using the full window. e.g. the result might look like this: (my text box is this big) ---------------------------------------------V (my wrap point is initially set here)-----------------V Did you ever live in another country? If so, please tell about that experience. No. ~ Did you ever travel overseas to countries that speak different languages than your native language? If so, please tell about your experience. Yes. I went to Europe and visited England, France, Italy and Germany with very brief stops in Switzerland and Austria. Mostly we managed quite well speaking English and with our primitive French. Bonjour! The idea is that the person reading the answers can easily see the Yes or No and can then read the text for the Yes answers. At the same time, it minimizes the size of the output in printed pages. Incidentally, the Yes/No and the detailed answers are substituted from <TAG>s as described above. Ideally I want to do this using variable fonts (I can do it without too much difficulty with a fixed font). I suppose that this is possible as I saw a function somewhere(the name of which I forget) that returns the pixel length of a string so I can keep adding another word until I pass the place that I want to stop and then take one word back, chuck in a NL and carry on. Ray