Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9321135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:47:38+00:00 2026-06-19T03:47:38+00:00

I have a database column which can take only 40 characters of a string.

  • 0

I have a database column which can take only 40 characters of a string. So when the length of string is greater than 40 characters, its giving me error. How can I cut/trim the string to 40 characters in delphi?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T03:47:39+00:00Added an answer on June 19, 2026 at 3:47 am
    var
      s: string;
    begin
      s := 'This is a string containing a lot of characters.'
      s := Copy(s, 1, 40);
      // Now s is 'This is a string containing a lot of cha'
    

    More fancy would be to add ellipsis if a string is truncated, to indicate this more clearly:

    function StrMaxLen(const S: string; MaxLen: integer): string;
    var
      i: Integer;
    begin
      result := S;
      if Length(result) <= MaxLen then Exit;
      SetLength(result, MaxLen);
      for i := MaxLen downto MaxLen - 2 do
        result[i] := '.';
    end;
    
    var
      s: string;
    begin
      s := 'This is a string containing a lot of characters.'
      s := StrMaxLen(S, 40)
      // Now s is 'This is a string containing a lot of ...'
    

    Or, for all Unicode lovers, you can keep two more original characters by using the single ellipsis character … (U+2026: HORIZONTAL ELLIPSIS):

    function StrMaxLen(const S: string; MaxLen: integer): string;
    var
      i: Integer;
    begin
      result := S;
      if Length(result) <= MaxLen then Exit;
      SetLength(result, MaxLen);
      result[MaxLen] := '…';
    end;
    
    var
      s: string;
    begin
      s := 'This is a string containing a lot of characters.'
      s := StrMaxLen(S, 40)
      // Now s is 'This is a string containing a lot of ch…'
    

    But then you must be positive that all your users and their relatives support this uncommon character.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my database I have a time stamp column...which reflects a format like this:
I have a textbox which is binded to a specific database table column. This
I have a database table named 'student' in which there is one column named
i have a large mysql database table in which one column contains values ranging
We have a Oracle 9i database and OrderDetails table which has a column to
we have a table in an Oracle Database which contains a column with the
I have a table in SQLite database of Android which has a column RANK
I have a column type money in my sql server database, which is moneyAcumulated
On my MySQL database, I have a unsigned mediumint column, which I keep incrementing
Here's the issue. I have a database column called pymnt_meth_pref, which contains a comma

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.