Recent

Author Topic: Remove last character from a string.  (Read 50212 times)

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: Remove last character from a string.
« Reply #15 on: July 18, 2011, 10:01:07 am »
I wonder how the new book on Lazarus (in English) relates to this.

I think it'd help if the List of Contents were in the web, and maybe a few sample pages.

Zoran

  • Hero Member
  • *****
  • Posts: 1980
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Remove last character from a string.
« Reply #16 on: July 18, 2011, 10:03:45 am »
I wonder how the new book on Lazarus (in English) relates to this.

I think it'd help if the List of Contents were in the web, and maybe a few sample pages.

http://www.blaisepascal.eu/lazarus/ContentPage5_10.pdf
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: Remove last character from a string.
« Reply #17 on: August 07, 2011, 04:49:44 am »
SetLength(Edit1.Text, Length(Edit1.Text) - 1);

Hi dear forum people,

I tried this:
SetLength(FormX.TextEntry.Text, Length(FormX.TextEntry.Text) - 1);

And I get error as follows:
UnitX.pas(166,36) Error: Can't take the address of constant expressions

I searched and found that Properties can not be passed by reference. So I suppose I have to set a var to have the value, and so forth. Am I supposing right, or is there a better way?

Also, I suspect that some functions can not use the properties directly, so I'd be aware of this?

But more than not, I suspect I may be misguiding myself, and hope a sentence or two from you good people, can provide some fundamental grasp.

Thanks.





Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Remove last character from a string.
« Reply #18 on: August 07, 2011, 05:42:31 am »
Quote
I searched and found that Properties can not be passed by reference. So I suppose I have to set a var to have the value, and so forth. Am I supposing right, or is there a better way?
Yep, you're right ;)

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: Remove last character from a string.
« Reply #19 on: August 07, 2011, 06:41:40 am »
Thanks LeleDumbo. ;)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12142
  • Debugger - SynEdit - and more
    • wiki
Re: Remove last character from a string.
« Reply #20 on: August 07, 2011, 11:43:48 am »
Code: Pascal  [Select][+][-]
  1. MiString := Copy (Edit1.Text,0,(length(Edit1.text)-1));
  2.  

Will not work always. Because Edit.Text is UTF8.

This removes the last BYTE from the string, but a utf8 char be multiply bytes.

Lazarus has somewhere (not sure which unit) CopyUtf8, etc => but be aware, that they are significantly slower.

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: Remove last character from a string.
« Reply #21 on: August 07, 2011, 04:41:30 pm »
Code: Pascal  [Select][+][-]
  1. MiString := Copy (Edit1.Text,0,(length(Edit1.text)-1));
  2.  

Will not work always. Because Edit.Text is UTF8.

This removes the last BYTE from the string, but a utf8 char be multiply bytes.

Lazarus has somewhere (not sure which unit) CopyUtf8, etc => but be aware, that they are significantly slower.

Good warning, Martin.

It's an important one, and will be kept in mind.

 

TinyPortal © 2005-2018