How to extract characters from the middle of a string?

Alex Tweedly alex at tweedly.net
Wed Jul 7 19:18:42 EDT 2004


At 17:15 07/07/2004 -0500, J. Landman Gay wrote:

>On 7/7/04 4:37 PM, Marian Petrides wrote:
>
>>If I have a string containing 25 characters, how do I extract the eight 
>>characters starting at position 5 in the string?
>>[In BASIC this would be left$(5,8)  or some such.]
>>This should be a simple thing to do but I can't figure it out and can't 
>>figure out which dictionary item applies.
>
>By the way, the exact phrase you needed was under "character" in the 
>transcript dictionary. Did you look up "character"?

Possibly not - every other language I've used (somewhere beyond 20 of them 
professionally and a few more just to look at)  has done this with either
    a function - e.g. substr(name, start, end) or Sub(name, start, len)
or
    a bit of punctuation  e.g.  name(5,8) or name[5:12] or ...
or
  a method  e.g. name.substr(5,8)

Some of them may have used character to extract a single character, but I 
can't think of another one that used the word "character" (or even 
characters) to extract a substring
and for many of them, searching their docs using "character" wouldn't have 
helped.

So maybe if I was less experienced, I'd have tried that first .... :-)

How quickly do you find the answer in the Rev docs by searching for
   substring
   section of a string
   part of a string
   string
   ...

-- Alex.
-------------- next part --------------

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.714 / Virus Database: 470 - Release Date: 02/07/2004


More information about the use-livecode mailing list