Get the length of arrays and a string

CK1820 
Created at Aug 22, 2009 13:18:13
Updated at Jan 15, 2024 02:48:17 
214   0   0   0  

The length function returns either the number of characters in Source String, or the number of elements in Source Array.

Notes: Arrays start at index=0 by default, So the length of such an array is 1 more than the highest index.

Following is the simple example to get the length of arrays and a string

var
  openArray  : array of char;
  fixedArray : array[2..4] of Integer;
  multiArray : array[2..4, 1..9] of Integer;
  shortStr   : shortstring;
  longStr    : string;
  i          : Integer;

begin
  // Define the length of the open array
  SetLength(openArray, 17);

  // Show the length of the arrays
  ShowMessage('Length of openArray = '+IntToStr(Length(openArray)));
  ShowMessage('Length of fixedArray = '+IntToStr(Length(fixedArray)));
  ShowMessage('Length of multiArray = '+IntToStr(Length(multiArray)));

  // Assign to the strings
  shortStr := 'ABCDEFGH';
  longStr  := '12345678901234567890';
  ShowMessage('Length of shortStr = '+IntToStr(Length(shortStr)));
  ShowMessage('Length of longStr = '+IntToStr(Length(longStr)));

  // Display one letter at a time from the short string
  for i := 1 to Length(shortStr) do
    ShowMessage('Letter '+IntToStr(i)+' = '+shortStr[i]);
end;


 



Tags: Browser Name Browser Version Delphi Dialog Total number of elements in array strlen Share on Facebook Share on X

◀ PREVIOUS
Delphi Pointer Types
▶ NEXT
How to resize PNG file in Delphi ?
  Comments 0
Login for comment
SIMILAR POSTS

Delphi Pointer Types (created at Aug 22, 2009)

How to read/wrtie INI file in Delphi ? (created at Aug 20, 2009)

How to get file created time, modified time, and last accessed time ? (created at Aug 19, 2009)

How to resize PNG file in Delphi ? (created at Sep 03, 2009)

Delphi API to get the current working directory (created at Sep 03, 2009)

Delphi API to get windows temporary directory (created at Sep 03, 2009)

How to print external document ? (created at Sep 08, 2009)

How to launch application ? (created at Sep 08, 2009)

Is there directory selection VCL component in Delphi ? (created at Sep 08, 2009)

Delphi string conversion functions - AnsiToUTF-8, UTF8Encode, ... (created at Jul 20, 2009)

When subject is crashing in TIdSMTP VCL (created at Jul 20, 2009)

How to send text/html based email in UTF-8 with TIdSMTP, TIdMessage VCL (created at Jul 20, 2009)

How to encode subject content when sending mail with TIdMessage ? (created at Jul 16, 2009)

Base64 Encoding/Decoding function for Delphi (created at Jul 16, 2009)

How to send email by TIdSMTP VCL ? (created at Jul 07, 2009)

How to return exit code such as exit() function in C/C++ ? (updated at Jan 15, 2024)

How to get parameter string ? (created at Jun 30, 2009)

Save TBitmap image to Jpeg format image in Delphi (created at Jun 25, 2009)

Thread Application Implementation in TThread (created at Apr 14, 2010)

How to get screen resolution in case of using multiple monitors ? (created at Dec 16, 2008)

How to turn off monitor ? (created at Dec 10, 2008)

Find File at certain directory in Delphi (created at Oct 10, 2008)

Auto Logon Programming in Delphi (created at Dec 31, 2010)

Changing the Title of a Print Dialog in Delphi (created at Apr 20, 2011)

I want to select directory(folder) not file. How can I do that ? (created at Apr 29, 2011)

The Delphi function to get My Videos folder (created at Apr 29, 2011)

Sending email messages in .Net (created at Oct 03, 2007)

Implementing C#'s foreach loop in Delphi 8 (created at Oct 03, 2007)

Delphi for .Net Code Folding keyboard shortcuts (created at Oct 03, 2007)

How to encrypt a string (created at Oct 03, 2007)

OTHER POSTS IN THE SAME CATEGORY

Delphi Program can command level execution program with hidden mode (updated at Jan 15, 2024)

How To Turn On/Off Monitor with Delphi (updated at Mar 09, 2024)

How to get application version number in Delphi (updated at Mar 09, 2024)

The Delphi function to get My Videos folder (created at Apr 29, 2011)

Get Application Data Path on Delphi (updated at Mar 09, 2024)

I want to select directory(folder) not file. How can I do that ? (created at Apr 29, 2011)

Changing the Title of a Print Dialog in Delphi (created at Apr 20, 2011)

Auto Logon Programming in Delphi (created at Dec 31, 2010)

Thread Application Implementation in TThread (created at Apr 14, 2010)

Is there directory selection VCL component in Delphi ? (created at Sep 08, 2009)

How to launch application ? (created at Sep 08, 2009)

How to print external document ? (created at Sep 08, 2009)

Delphi API to get windows temporary directory (created at Sep 03, 2009)

Delphi API to get the current working directory (created at Sep 03, 2009)

How to resize PNG file in Delphi ? (created at Sep 03, 2009)

Delphi Pointer Types (created at Aug 22, 2009)

How to read/wrtie INI file in Delphi ? (created at Aug 20, 2009)

How to get file created time, modified time, and last accessed time ? (created at Aug 19, 2009)

Delphi string conversion functions - AnsiToUTF-8, UTF8Encode, ... (created at Jul 20, 2009)

When subject is crashing in TIdSMTP VCL (created at Jul 20, 2009)

How to send text/html based email in UTF-8 with TIdSMTP, TIdMessage VCL (created at Jul 20, 2009)

How to encode subject content when sending mail with TIdMessage ? (created at Jul 16, 2009)

Base64 Encoding/Decoding function for Delphi (created at Jul 16, 2009)

How to send email by TIdSMTP VCL ? (created at Jul 07, 2009)

How to return exit code such as exit() function in C/C++ ? (updated at Jan 15, 2024)

How to get parameter string ? (created at Jun 30, 2009)

Save TBitmap image to Jpeg format image in Delphi (created at Jun 25, 2009)

How to get screen resolution in case of using multiple monitors ? (created at Dec 16, 2008)

How to turn off monitor ? (created at Dec 10, 2008)

Find File at certain directory in Delphi (created at Oct 10, 2008)

UPDATES

Creating a Pinterest-Style Card Layout with Bootstrap and Masonry (created at Apr 24, 2024)

Mastering Excel Data Importation in PHP (updated at Apr 24, 2024)

JSON format control in PHP (updated at Apr 24, 2024)

Equal Height Blocks in Bootstrap with JavaScript (created at Apr 22, 2024)

How to convert integer to text string ? (updated at Apr 22, 2024)

Checking similarity between two strings in PHP (updated at Apr 21, 2024)

Create Blob Image in HTML based on the given Text, Width and Height in the Center of the Image without saving file (updated at Apr 21, 2024)

How do I determine the client IP type (IPv4/IPv6) in PHP (updated at Apr 16, 2024)

How do I determine the client IP type in Python - IPv4 or IPv6 (updated at Apr 13, 2024)

Getting Started with PyTorch: A Beginner's Guide to Building Your First Neural Network (updated at Apr 09, 2024)

Predicting Buyer Preferences with PyTorch: A Deep Learning Approach (updated at Apr 09, 2024)

Forecasting the Weather with PyTorch: A Beginner's Guide to Temperature Prediction (created at Apr 09, 2024)

PyTorch example to Forcast Stock Price based on 10 days Dataset (created at Apr 09, 2024)

Mastering Model Persistence: Saving and Loading Trained Machine Learning Models in Python (created at Apr 08, 2024)

Harnessing the Power of Random Forest Algorithm in Python (created at Apr 08, 2024)

Understanding and Implementing K-Nearest Neighbors (KNN) Algorithm in Python (created at Apr 08, 2024)

Forecasting with Linear Regression and KNN Regression in Python (updated at Apr 07, 2024)

What is 302 Found Redirection in HTTP 1.1? (created at Apr 04, 2024)

Mastering Random Forest Regression: A Comprehensive Guide with Python Examples (updated at Apr 01, 2024)

Python Implementation of Linear Regression (updated at Apr 01, 2024)

Mastering Supervised Machine Learning with Python: A Comprehensive Guide (created at Apr 01, 2024)

Mastering AI: A Beginner's Guide to Python Programming and Beyond (created at Apr 01, 2024)

How do I create animated background for Google Meet? (updated at Mar 28, 2024)

Building a Simple DNS Server in Delphi with TTL Support (created at Mar 16, 2024)

How to force cookies, disable php sessid in URL ? (updated at Mar 16, 2024)

Implementing a Versatile DNS Server in PHP: Handling A, AAAA, CNAME, and TXT Records (updated at Mar 16, 2024)

Implementing a Versatile DNS Server in Python: Handling A, AAAA, CNAME, and TXT Records (created at Mar 16, 2024)

Building a Basic DNS Server in PHP/Python: A Beginner's Guide (updated at Mar 15, 2024)

Dynamic DNS Made Easy: Building a Python-Based Solution (created at Mar 15, 2024)

Exploring the Depths of Data Transfer: sendfile vs. kTLS (created at Mar 15, 2024)