delphi XE的字符串处理

最近用delphi xe做了个东西,因为以前一直使用Delphi 7做开发,delphi 7 到delphi XE有了很大的变化,最大的变化就是对Unicode的支持,所以刚开始使用DELPHI XE时还有些不太习惯,尤其在字符串处理的时候。

DELPHI XE 增加了UnicodeString 类型,这在Delphi 7中是没有的,默认的String字符串为UnicodeString,而String在Delphi 7中是AnsiString类型,在新版的DELPHI中,字符串的存储格式也发生了变化:

在DELPHI7中,字符串的存储格式是这样子的:

【引用计数位(-8byte)】【字符串长度(-4byte)】【字符串内容】

这一结构在DELPHI2009时发生了变化,增加了代码页、元素长度两部分内容:

【代码页(-12byte)】【元素长度(-10)】【引用计数位(-8byte)】【字符串长度(-4byte)】【字符串内容】

在新版本的DELPHI中,不论是UnicodeString类型还是AnsiString类型,都遵循上面结构,不同之处是元素长度部分,UnicodeString类型元素长度部分为2,而AnsiString类型元素长度部分为1,也就是说,Unicode字符串中每个字符占用两个字节的位置,而AnsiString占用一个字节的位置。

除了UnicodeString字符串类型外,在新版本的Delphi中,还增加了RawByteString字符串类型,RawByteString字符串类型有什么特殊的用途呢?在查看DELPHI源码时,我们可以看到其定义:
RawByteString = type AnsiString($FFFF);
由此可见,可以认为RawByteString类型是以AnsiString类型为基础的,其特点是不管传入的字符串的代码页是什么,RawByteString字符串会原封不动的保持传入数据的原样。这里说明一下:type AnsiString(【代码页】)可以定义不同代码页的字符集编码,例如:
GbkString = type AnsiString(936);
就是定义了Gbk编码的字符集,当我们为GbkString类型的变量传入字符串时,其存储格式就会按照GBK编码进行存储。
 
https://www.cnblogs.com/MaxWoods/archive/2013/09/06/3305505.html

转载于:https://www.cnblogs.com/railgunman/p/9931265.html

delphi XE的字符串处理.mht 立即下载

相关推荐

Delphi演示UniCode编码、简体繁体互转的方法实现.rar

Delphi演示如何实现UniCode编码、汉字的繁简互转功能,同时将字符转换为unicode码值(十六进制):   常用编码:   codepage=936 简体中文GBK   codepage=950 繁体中文BIG5   codepage=437 美国/加拿大英语   codepage=932 日文   codepage=949 韩文   codepage=866 俄文   codepage=65001 unicode UTF-8   本例子中仅使用了936、950,如果你要进行其他语言的编码转换,仅需相应改变其中的编码值即可。

Delphi Xe的字符及字符串[1] - string、AnsiString、WideString、String[n]、ShortString

最常用的 string,以前版本(2007)中的默认状态下, String 就是 AnsiString,Xe版本String就是WideString。注意:DelphiXE中使用UniCodeString下标引用得到的字符的值,而使用AnsiString下标引用得到的却是字节的值。 AnsiString实质上是一个指针类型,与普通的指针不同,此类型的指针专用于指向字符串。利用标准函数SizeOf()可知此类型变量在内存中占用4个字节。所以AnsiString最小值为4byte,而非0byte,也就是说,一

turbocc 因程序而激情 3002

爬虫-Playwright逆向小红书

【代码】爬虫-Playwright逆向小红书。

weixin_44201223的博客 2433

Delphi7 To Delphi XE的变化

Delphi7转移到Delphi XE, 从代码上看,一个变化就是对Unicode(从此用Delphi编写乱码的问题,国际化问题算是彻底解决了)。 特别是代码中喜欢用PChar的同学要注意了,在XE中PChar默认都是PWideChar,而Delphi7中指向PAnsiChar的。 关于Delphi XE的Unicode说明可以下面的一篇资料,讲的很详细了 http://www.china

东子的博客 8858

AutoCAD2014与ObjectARX开发环境搭建实战指南

本文提供了一份详细的AutoCAD2014与ObjectARX开发环境搭建实战指南。内容涵盖从AutoCAD2014、Visual Studio 2010及ObjectARX 2014 SDK的版本匹配与环境准备,到Wizard安装、编码问题解决、Visual Studio配置,并最终通过一个完整的绘图命令开发示例,手把手引导开发者创建并加载第一个可运行的ObjectARX插件,为后续深入开发奠定坚实基础。

weixin_28475533的博客 289

ABtest描述统计功效

我们在面试数据分析时,常常会问到如何确定样本量的问题,会有一个指标:统计功效(power),或者是1-β 统计功效会影响实验的可信度,甚至会影响实验所需的样本量,要了解统计功效,首先要理解两类统计错误 假如我们做了一个AB实验,且两组用户的数据均值为μ1和μ2,我们会有两个初始假设: H0:两个实验组的数据没有差别(μ1=μ2),这个假设也叫“零假设”,也叫原假设 H1:两个实验组之间的数据存在差别(μ1≠μ2),这个假设也叫“非零假设”,也叫备择假设 定义两类错误: 实验本身没有效应,但我们觉

qq_38134556的博客 905

DelphiXE下的字符串变化

DelphiXE下的字符串变化

敦格 8418

YOLOv11改进,YOLOv11引入B2CNet的BFAM(双时相特征聚合模块),JSTARS 2024,二次创新C3k2结构

YOLOv11改进,YOLOv11引入B2CNet的BFAM(双时相特征聚合模块),JSTARS 2024,二次创新C3k2结构

在职AI算法工程师,擅长计算机视觉,YOLO目标检测、分割等,擅长web、pyqt界面可视化,好内容持续更新中,来这里跟大家一起学习,共同进步 411

当Delphi支持了Unicode,它将会变成什么样子呢?

 当Delphi支持了Unicode,它将会变成什么样子呢?我的看法如下:1. 开发变得复杂了,因为要更多的考虑编码问题2. 绝大多数控件都需要修改,以使其能适应Delphi20093. 多国语言的软件得到了较好的支持第一点和第二点,相信很多人都有体会了,原本在Delphi2007上通顺利编译通过的项目,放到Delphi2009上就要进行很大的改动。特别是API的调用,MessageBoxA改

Hopping的专栏 3023

军品研制过程-转阶段

介绍军品转阶段评审

Abel的博客 2万+

MTK Meta ISP 工具使用技巧与参数读取路径全解析

在联发科(MediaTek, MTK)平台上进行相机图像调试时,Meta ISP 工具是连接 PC 与设备进行参数调整、寄存器读取和图像输出的重要工具。本文以实战角度出发,系统梳理 Meta ISP 的使用流程、关键模块功能、典型调试技巧与参数读取路径,结合最新版平台(如MTK Genio/Dimensity 系列)架构,帮助工程师掌握联发科图像调优的核心流程。

努力分享一些人工智能、计算机视觉、影像等相关的知识干货! 1154

DelphiXE开发坑

1.字符类型不同 在 Delphi2010 之前,默认PChar是PAnsiChar。在之后PChar 是一个指向 Char 的指针,它是一个unicode字符(一个 WideChar )。而 PAnsiChar 是一个指向 AnsiChar 的指针。

weixin_43487532的博客 1301

-bash: mysql: 未找到命令

解决问题,😀

知识改变命运,ヾ(◍°∇°◍)ノ゙【求关注】 1350

Delphi 7 和 Delphi 2007/2009/2012(XE3) 的区别

Delphi 7    Delphi 2007/2009/2012(XE3) 版本历史 Delphi 2007 (Delphi 11), the first version byCodeGear, was released on March 16, 2007.   Delphi 2009 (Delphi 12,),the first version byEmbarca

lixianhuo的专栏 3462

背靠背VSC直流母线电压控制与同步发电机并网发散问题:原理、分析与解决方案

背靠背VSC直流母线电压控制与同步发电机并网发散问题分析 摘要: 本文研究了背靠背VSC系统在整流侧由理想三相电源切换为同步发电机时出现的直流母线电压振荡和发散问题。通过理论分析发现,锁相环同步失稳、等效阻抗失配和直流母线电容参数失配是导致系统失稳的关键因素。当整流侧接入同步发电机后,系统形成正反馈振荡回路,同时等效电感增大导致电流环响应速度降低,直流侧电容容量不足无法吸收发电机功率波动。文章提出了从跟网型控制到构网型VSG控制的完整升级方案,包含详细的MATLAB/Simulink建模和控制算法实现,并通

huanghm88的专栏 122

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

delphi xe 通过注册表到得硬盘型号与序号 处理字符串 删除多余下划线

注:上篇用delphi xe 通过注册表到得硬盘型号与序号  是在WIN7 64位下通过,WIN10的DISK字符串与WIN7获得的字符串不一致。所以要检测系统版本,根据系统的版本,处理解决之。   以下是解决WIN7时的处理方法:     unit Unit4; interface uses   Winapi.Windows, Winapi.Messages, System.Sys...

qq457565758的博客 368

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

XE2 和D7 的对比:

string 将会默认为 widestring 而在D7 中string 是ansistring char 认为 widechar; XE2有三种字符串:ansistring,widestring,UnicodeString (新增) XE2 多了一个UicodeString d7   TTypeKind = (tkUnknown, tkInteger, tkChar, tkEnu

hrdzkj的专栏 1981

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

zw.delphi不同版本程序运行速度测试

{ zw.delphi不同版本程序运行速度测试 delphi无论是开发,编译,还是运行,速度方面向来不差,笔者很少进行这种微粒度的优化,调试、 最近,因为项目需要,发现:同一个函数模块,差不多同样的代码,升级后,比2007慢2-3倍 涉及字符串、thashedlist,起初,感觉是uncode字符串函数,替换qstring函数的问题。 测试后,发现...

weixin_34343308的博客 231

delphi7代码 转XE代码需注意:

delphi7 char xe AnsiChar delphi7 strcopy(@jpginfo.szCarNumber,pAnsiChar(@tempstr[1])); xe CopyMemory(@jpginfo.szCarNumber[0],PAnsiChar(AnsiString(tempstr)),Length(AnsiString(tempstr))...

9807146wang的专栏 596

delphi 字符串截取的问题

i:=len-1; while True do begin if InputStr[i]='\' then begin iPos:=i; Break; end; i:=i-1; end; //method_A inum:=len-ipos; outstr:=RightStr(InputStr,inum); //meth...

ylbxxq的博客 617

【无标题】

Delphi2007和XE字符串乱码原因

Amelie_W的博客 350

delphi xe 遍历指定文件夹下所有的文本文件内容

遇到 的小问题:想把所有PAS文件中包含‘c_AppEdition’内容的文件筛选出来 用DELPHI XE10.3处理代码如下,当作笔记本 unit Unit12; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics...

qq457565758的博客 1891

delphi MD5加密,BASE64加解密

MD5需要引入system.Hash,BASE64需要引入System.NetEncoding,这两个单元应该只有高版本的DELPHI IDE才有(貌似XE5以上版本才有)。如果是D7的话,找第三方的库。 procedure TForm19.Button8Click(Sender: TObject); //md5加密 begin Edit3.Clear; Ed...

aldsot0997的博客 614
上一篇: 如何判断可见字符 Unicode
下一篇: cxgrid多选删除
aowo7144
博客等级 码龄10年 5粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值