怎样一个字符串的宽度
解决方案 »
- 给[dinglinger]补上五一过节的分,呵呵
- 有谁知道这个案例用了什么加密算法,MD5还是DES
- 请问斑竹申请斑竹需要什么?
- 多线程数据库查询
- adotable连接oracle数据库,一个类型为NUMBER(18)字段显示为BCD OVERFLOW
- 关于TStringGrid问题,我想修改TStringGrid中的某一列,其它列不能修改,这个怎么实现,谢谢!
- 高手帮忙:换project.dpr图示出问题!
- 请教如何用DELPHI启动时调用一个FLASH动画?
- 二个窗体的显示问题?
- 求安装程序的制作工具?(很急)
- 关于程序保存问题
- 急! 请问有什么办法能够取得某个web目录下的所有子目录及文件????
showmessage('中国人'+#13+'的长度为:'+Inttostr(Length('中国人')));
获取字符串在画布中所需的长度用Canvas.TextWidth()方法
类似的问题,怎么知道一个字符串中的字符个数,包括unicode
type
PInteger=^Integer;
var
P:Pointer;
PI:PInteger;
vInt : Integer;
vStrValue : String;
begin
vStrValue := 'asfsadfsad';
P := @vStrValue;
ShowMessage(IntToStr(PInteger(P)^));//----------------------
你用类如的方法看一下它的首地址和末尾地址,找差值。
如果要实际的宽度(毫米)可以用getdevicecaps获得输出设备的分辨率,然后换算。
补一点, 字符的 dpi 在 windows 下始终是 72dpi
Font.Size = -Font.Height * 72 / Font.PixelsPerInch
这是 borland 的字符公式
获取字符串在画布中所需的长度用Canvas.TextWidth()方法
是对的
不过不知道楼主要的是不是这个意思
我本来以为楼主是要fun()得到像字符串'test测试',fun('test测试')得到6
大家懂我的意思了吗??length('test测试')得到的是8
a :string; // ansi string
w :WideString; // wide string(unicode string)
begin
a := 'test测试';
w := a;
ShowMessage('a length:' + IntToStr(Length(a)) + #13 +
'w length:' + IntToStr(Length(w)));
end;那就是你想得到的效果
但... Borland 对 unicode 的支持不够全面,在一些情况下仍存在问题..
还乘以字号大小。
var
a :string; // ansi string
w :WideString; // wide string(unicode string)
fFontSize:integer;
begin
a := 'test测试';
w := a;
fFontSize:=Form1.Font.Size;
ShowMessage('a length:' + IntToStr(Length(a)*fFontSize) + #13 +
'w length:' + IntToStr(Length(w)*fFontSize)));
end;
font.size都是8啊,学习
Font.Size = -Font.Height * 72 / Font.PixelsPerInch因为screen的坐标系是左上角为(0,0),字符的top比bottom要小,所以height是negative啊,所以delphi的帮助里有说
When the Size property has a positive value, the Height property has a negative value. When the Height property has a positive value, the Size property has a negative value.不过什么时候size为negative就不了解了!!!Use Size to specify the point size of the font. If the value is negative, the internal leading that appears at the top of each line of text is included. If the value is positive, Size represents the height of the characters but not the internal leading.里面的internal leading也不知道是什么意思~~~太可怕再说啊!!
keke,偶生角了