Lazarus中system.length说明
在system单元中我们有Length专门用来获取字符串宽度和数组宽度,下面例子来介绍他的功能。
定义:
function Length( |
S: AStringType |
):Integer; function Length( |
A: DynArrayType |
):Integer; |
这里我们可以看到传递的参数可以是字符串,也可以是字符。
函数返回S字符串的宽度,如果字符串是shortstring类型,字符宽度限制在255以内,如果S是空,则返回0.
widestrings和ansistrings也可以使用这个函数
如果是动态数组,函数将会返回数组元素的数量。
Length函数同样支持Pchar和PWideChar类型,效果类似StrLen和WStrLen,但这种情况,函数只计算null结尾的字符串,因为这里的函数是一个null结尾扫描结果的函数。
官方例子:
Program Example36; {Program to demonstrate the Length function.} Var S :String;
I :Integer; begin
S:='';
for i:=1 to 10do
begin
S:=S+'*';
Writeln(Length(S):2,' : ',s);
end;
end.
下面是我们的例子:
program system_example; {$mode objfpc}{$H+} uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes,sysutils; var
s:string;
i:Integer;
ss:ShortString;
sarr : string[10];
anstr:AnsiString;
wdstr:widestring;
arr : array[0..10] of integer;
darr : array of integer;
marr : array[0..4,2..22] of integer;
begin
//normal string
s:='Lazarus';
i := length(s);
WriteLn('string length:'+inttostr(i)); //short string
ss:='Lazarus';
i := length(ss);
WriteLn('shortstring length:'+inttostr(i)); // string array
sarr:='Lazarus';
i := length(sarr);
WriteLn('string array length:'+inttostr(i)); // ansistring
anstr :='我的lazarus';
i := length(anstr);
WriteLn('ansi string length:'+inttostr(i)); // widestring
wdstr :='我的lazarus';
i := length(wdstr);
WriteLn('wide string length:'+inttostr(i)); //static array length
i:= length(arr);
WriteLn('array length:'+inttostr(i));{11} // dynamic array
setlength(darr,10);
i:= length(darr);
WriteLn('dynamic array length:'+inttostr(i));{10} i:= length(marr);
WriteLn('m array length:'+inttostr(i));{5}
end.
Lazarus中system.length说明的更多相关文章
- 分析Java中的length和length()
在不适用任何带有自动补全功能的IDE的情况下,我们怎么获取一个数组的长度?如何获取字符串的长度? 这里我们先举用实例去分析一下:int[] arr=new int[3]:System.out.prin ...
- Java 中System里getProperty(something)
Java 中System里getProperty 方法获得系统参数 Key Description of Associated Value 中文描述 java.version Java Runtime ...
- net中System.Security.Cryptography 命名空间 下的加密算法
.net中System.Security.Cryptography命名空间 在.NETFramework出现之前,如果我们需要进行加密的话,我们只有各种较底层的技术可以选择,如 Microsoft C ...
- C#中System.Globalization.DateTimeFormatInfo.InvariantInfo怎么用
原文 C#中System.Globalization.DateTimeFormatInfo.InvariantInfo怎么用 在开发的时候,碰到下面这样一个问题: 在程序中显示当前系统时间,但是有一 ...
- Java中System.getProperty()的参数
Java中System.getProperty的使用方法: 1,System.getProperty返回的数值,比如java.version,java.home,os.name,user.home以及 ...
- python中print()函数的“,”与java中System.out.print()函数中的“+”
python中的print()函数和java中的System.out.print()函数都有着打印字符串的功能. python中: print("hello,world!") 输出 ...
- Systemd初始化进程/RHEL 6系统中System V init命令与RHEL 7系统中systemctl命令的对比
Linux操作系统的开机过程是这样的,即从BIOS开始,然后进入Boot Loader,再加载系统内核,然后内核进行初始化,最后启动初始化进程.初始化进程作为Linux系统的第一个进程,它需要完成Li ...
- webConfig中System.Web 和 System.WebServer节点读取
webConfig中System.Web 和 System.WebServer节点读取根据应用程序池中托管管道模式有关. 在网站发布到服务器的IIS上时,应用程序池中托管管道模式分为经典和集成. Sy ...
- debug.js中的length的错误
记得昨天报了一个错,debug.js文件中的length未定义.前台不定位代码,后天也不报错,而debug.js是框架封装的文件,不是自己写的,无从得知是哪里的问题,而项目也已经重新启动过,无法撤销. ...
随机推荐
- 【HTML5】SVG内联
什么是SVG? SVG 指可伸缩矢量图形 (Scalable Vector Graphics) SVG 用于定义用于网络的基于矢量的图形 SVG 使用 XML 格式定义图形 SVG 图像在放大或改变尺 ...
- 【练习】使用接口回调和handler实现数据加载到listview
代码结构 布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xml ...
- eclipse常用快捷键,这个只要新学会的常用的会陆续更新的。
1.Ctrl+Shift+O 引用包 2.Ctrl+Shift+F 格式化代码 3.Ctrl + / 注释和解除注释代码 4.Ctrl+M 代码最大最小化 5.ctrl+shif ...
- node相关--测试
测试: assert模块; //node自带 var assert = require('assert'); var now = Date.now(); console.log(now); asser ...
- iOS汉字中提取首字母
NSMutableString *mutableStr = [[NSMutableString alloc]initWithString:string]; if (CFStringTransform( ...
- SQL 计算列
SQL计算列,可以解决一般标量计算(数学计算,如ColumnA*ColumnB)的问题,而子查询计算(如select sum(salary) from tableOther where id=’ABC ...
- 时间工厂[XDU1013]
Problem 1013 - 时间工厂 Time Limit: 1000MS Memory Limit: 65536KB Difficulty: Total Submit: 384 Acce ...
- strerror
#include<stdio.h> #include<string.h> #include<errno.h> void main(void ) { printf(& ...
- BZOJ2851 : 极限满月
把集合A[i]看作i点的前驱点集合,建成一个DAG,并新建超级源S,向每个前驱集合为空的点连边,那么B[i]就是S到i的必经点集合. 首先使用Lengauer-Tarjan算法建立出以S为起点的Dom ...
- BZOJ3325 : [Scoi2013]密码
从以每一位为中心的回文串长度可以用Manacher倒推出$O(n)$对相等和不等关系. 将相等的用并查集维护,不等的连边. 然后输出方案时若还没被染过色,则求一个mex. #include<cs ...