Recent

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

Elmug

  • Hero Member
  • *****
  • Posts: 849
Remove last character from a string.
« on: July 17, 2011, 12:45:14 pm »
I have a TEdit window that contains text. Let's say the text is Display.text and I want to remove the last char of Display.text.

I can't seem to find string function to do that. I can't even find string function that returns the number of characters in a string.

I am not sure if the old Delete string function of Turbo Pascal works?

I am sure there is these things in Lazarus, but in the web, can't seem to find it.

All I tried returns me errors.

Thanks for any help.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Remove last character from a string.
« Reply #1 on: July 17, 2011, 01:05:58 pm »
Hi Elmug,

For Delphi help (very similar to Lazarus):
http://docwiki.embarcadero.com/RADStudio/en/Delphi_Reference
... so (searching on that page with keywords delete Delphi):
http://docwiki.embarcadero.com/VCL/en/System.Delete

... seems like Delete is alive and well

A very good site with explanation of commands, and also examples:
http://www.delphibasics.co.uk/
(I got their offline reader, very handy for a Pascal noob like me)


HTH
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

BlueIcaro

  • Hero Member
  • *****
  • Posts: 834
    • Blog personal
Re: Remove last character from a string.
« Reply #2 on: July 17, 2011, 01:18:40 pm »
Hi,

Code: Pascal  [Select][+][-]
  1. MiString := Copy (Edit1.Text,0,(length(Edit1.text)-1));
  2.  
More info:
http://www.freepascal.org/docs.var

/BlueIcaro

jixian.yang

  • Full Member
  • ***
  • Posts: 173
Re: Remove last character from a string.
« Reply #3 on: July 17, 2011, 05:38:47 pm »
SetLength(Edit1.Text, Length(Edit1.Text) - 1);

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Remove last character from a string.
« Reply #4 on: July 17, 2011, 06:25:01 pm »
Quote
I am not sure if the old Delete string function of Turbo Pascal works?
Yes, it still works :) (and should be faster than Copy in this case)

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: Remove last character from a string.
« Reply #5 on: July 17, 2011, 07:03:25 pm »
Thanks everyone, I'll give them all a try and report back.

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: Remove last character from a string.
« Reply #6 on: July 18, 2011, 04:26:07 am »
Hi Elmug,

For Delphi help (very similar to Lazarus):
http://docwiki.embarcadero.com/RADStudio/en/Delphi_Reference
... so (searching on that page with keywords delete Delphi):
http://docwiki.embarcadero.com/VCL/en/System.Delete

... seems like Delete is alive and well

A very good site with explanation of commands, and also examples:
http://www.delphibasics.co.uk/
(I got their offline reader, very handy for a Pascal noob like me)


HTH

Thanks for the Link. I got it now.

The name SystemDelete trhew me off in my searchings before asking in this post, because when potential info came over, I thought the word "system" related to "operating system" or something like that.

So, it seems to me that here SystemDelete refers to an INCLUDED function of the Delphi Pascal? So in future searches, I would even maybe include the word "system" if I want to check the actual details, specially on original TurboPascal functions?

Meaning, should I expect the word "System" to be part of the terminology in similar cases?

Thanks a lot!

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Remove last character from a string.
« Reply #7 on: July 18, 2011, 04:49:55 am »
The name SystemDelete trhew me off in my searchings before asking in this post, because when potential info came over, I thought the word "system" related to "operating system" or something like that.

So, it seems to me that here SystemDelete refers to an INCLUDED function of the Delphi Pascal? So in future searches, I would even maybe include the word "system" if I want to check the actual details, specially on original TurboPascal functions?

Meaning, should I expect the word "System" to be part of the terminology in similar cases?

Thanks a lot!
System in this context means the unit in which the code resides. Delphi and Lazarus/FPC differ in that respect; functions that are in Delphi System might be in other units in Lazarus (probably some operating system-dependent units).
So no, searching on System will probably not help... However, somebody else posted a link to the FPC pdf/html documentation, which will tell you where to find the relevant function.
Also, I use the DelphiBasics site a lot to look for alternatives; sometimes there is more than 1 function/method that might be suitable.
(And yes, Delphi probably includes the System unit by default, just as Lazarus uses some units by default).
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: Remove last character from a string.
« Reply #8 on: July 18, 2011, 05:17:39 am »
Thanks for the generous and very clear explanation, BigChimp.

I got it.

In fact, after further solving my little problem (mainly of being newbie in this IDE things), I did notice that although the title is SystemDelete, down at the bottom they call it System.Delete, which fully checks with what you are saying.

And I suppose, hopefully not misleading myself, that if they are included by default, the word "system" can be dropped out, or as in Lazarus/Free-Pascal, whatever unit owns "Delete", does not need to be named; or maybe in special cases to make things double sure.

Thanks a lot!

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Remove last character from a string.
« Reply #9 on: July 18, 2011, 07:15:56 am »
Free Pascal also has documentation on the Delete function:

http://www.freepascal.org/docs-html/rtl/system/delete.html

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: Remove last character from a string.
« Reply #10 on: July 18, 2011, 07:25:41 am »
Thanks Felipe,

I appreciate your mentioning it!

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Remove last character from a string.
« Reply #11 on: July 18, 2011, 08:27:33 am »
Just chipping in on this topic: does anyone know a complete list of all functions/procedures (maybe even also properties and methods) of the FreePascal runtime library (RTL), and packages/Free Component Library (FCL) along with a one line description?

I really like the DelphiBasics site mentioned earlier because it does provide a searchable list for that. I had a hard time looking for e.g. string functions in System while they are also in strutils, and maybe other units as well...

(Ok, thinking about it, maybe it could be generated out of the help sources. Maybe it is generated out of these sources and available somewhere)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Remove last character from a string.
« Reply #12 on: July 18, 2011, 08:33:52 am »
Just chipping in on this topic: does anyone know a complete list of all functions/procedures (maybe even also properties and methods) of the FreePascal runtime library (RTL), and packages/Free Component Library (FCL) along with a one line description?

I really like the DelphiBasics site mentioned earlier because it does provide a searchable list for that. I had a hard time looking for e.g. string functions in System while they are also in strutils, and maybe other units as well...

(Ok, thinking about it, maybe it could be generated out of the help sources. Maybe it is generated out of these sources and available somewhere)

The list for all functions would be simply enormous ... but surely you can add a list, for example, of "string functions" to the wiki, with adequate links to the documentation.

Zoran

  • Hero Member
  • *****
  • Posts: 1985
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Remove last character from a string.
« Reply #13 on: July 18, 2011, 09:33:37 am »
(And yes, Delphi probably includes the System unit by default, just as Lazarus uses some units by default).

Not only in Delphi, but also in FPC, every unit implicitly uses System unit. Further, in Objfpc and Delphi modes, unit Objpas is also implicitly used.

Just chipping in on this topic: does anyone know a complete list of all functions/procedures (maybe even also properties and methods) of the FreePascal runtime library (RTL), and packages/Free Component Library (FCL) along with a one line description?

There is FCL reference. You have list of units there and by clicking on any of these units, you get (top left of the page) links to functions/procedures, properties, methods of that unit.
There is also index page with all identifiers of fcl.

The similar you have for RTL and LCL.
« Last Edit: July 18, 2011, 10:02:03 am by Zoran »
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Remove last character from a string.
« Reply #14 on: July 18, 2011, 09:56:52 am »
Thanks Felipe & Zoran,

I understand the list of functions would be enormous, but it does make it easier to search, especially if you have a list of functions, the unit they're in and a short description.
I realize I can add it to the wiki, but it might be easier to maintain to automatically extract them from the documentation, or maybe even the unit source code.

The documentation already has the necessary data:
- Page with identifiers for the FCL, etc, as posted by Zoran
- Detail pages like
http://www.freepascal.org/docs-html/fcl/db/extractfieldname.html
have a one line description.

"Just" a question of pasting it al together  :)

Maybe I'll get to it some day...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018