string variables 
Author Message
 string variables

Why is it that no programming language has one simple interface for dealing
with
stupid character strings?

After reading through documentation for an hour, I finally tried some
simple string
manipulation just as given in the online help example for the Copy
function. . .

var
  last: string;

last := Copy(S,1,i);

The compile time error says that 'Left side cannot be assigned to.'
I've wasted enough time at this. . . can someone please clue me in on
how to take a string such as 'Smith, Tom' and parse out the first and last
names??
I feel stupid just asking the question . . could have written it in 2
minutes in C.

Thanks



Wed, 18 Jun 1902 08:00:00 GMT  
 string variables

Quote:

>Why is it that no programming language has one simple interface for dealing
>with stupid character strings?

Lots of them do. Simula and Java spring to mind, as does Perl (well, simple is
perhaps not the word, but _good_ is.) Snobol is also good for string manipulation.

Quote:
>var
>  last: string;

>last := Copy(S,1,i);

This compiles just fine for me with Delphi 2.0. Perhaps you should post the entire
program? The error might be caused by something other than those three lines.

Quote:
>The compile time error says that 'Left side cannot be assigned to.'
>I've wasted enough time at this. . . can someone please clue me in on
>how to take a string such as 'Smith, Tom' and parse out the first and last
>names??

VAR
  i : INTEGER;
  first,last : STRING;
  fullname : STRING;
BEGIN
  i:=Pos(',',fullname);
  first:=Copy(fullname,1,i-1);
  last:=Copy(fullname,i+2,Length(fullname)-i-1);
END;

This should work, I even compiled and ran it. It's not fast, however. If you want to
do it fast, you do better to do it C-style by running a pointer along the fullname
string and copying characters as you pass them to first and last according to where
you are in the string (ie: before or after ', ').

--
_______________________________________________________________________________
       Lars Marius Garshol
       "Make it idiot proof and someone will make a better idiot", Bill Arnett
       http://www.ifi.uio.no/~larsga/        http://birk105.studby.uio.no/



Wed, 18 Jun 1902 08:00:00 GMT  
 string variables

Quote:

> Why is it that no programming language has one simple interface for dealing
> with
> stupid character strings?

> After reading through documentation for an hour, I finally tried some
> simple string
> manipulation just as given in the online help example for the Copy
> function. . .

> var
>   last: string;

> last := Copy(S,1,i);

> The compile time error says that 'Left side cannot be assigned to.'
> I've wasted enough time at this. . . can someone please clue me in on
> how to take a string such as 'Smith, Tom' and parse out the first and last
> names??
> I feel stupid just asking the question . . could have written it in 2
> minutes in C.

> Thanks


Your code should work. Note however that 'last' is a method name applied to
TList and TTable, TQuery, etc...

Perhaps your code that contains the assignment is within a 'with ... do'
statement, where the 'last' identifier is a method call instead of the intended
variable. I just tried this one and got the same error message.

Rename your variable to Last_Name or something and try again. :-)

/Kiina



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Pascal refuses to read a string variable...

2. Loading 12000 string variables in memory.

3. How Do I copy one field value to a string variable

4. Variable length strings to DLLs

5. how to use strings/arrays of variable length?

6. Passing string from DBF field to a variable (Halcyon 4.0)

7. a variable variable...

8. a variable variable...

9. Variables about variables

10. pchar := string; string:=pchar

11. How to convert strings to nul-terminated strings?

12. String vs. String literal

 

 
Powered by phpBB® Forum Software