AnsiString使用大全_第1页
AnsiString使用大全_第2页
AnsiString使用大全_第3页
AnsiString使用大全_第4页
AnsiString使用大全_第5页
已阅读5页,还剩5页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、ansistring使用大全 :顾名思义,就是利用 ansistring 来处理相关的各种问题。来看看吧,一定让你受益匪浅!/ansistring转 charvoid _fastcall tform1:button1click(tobject *sender)ansistring test = 哈哈 ;char *chr = test.c_str();/char转 ansistring#includevoid _fastcall tform1:button1click(tobject *sender)ansistring str = sample;char chrmax_path;strcpy

2、( chr , str.c_str() );/bool转 ansistringvoid _fastcall tform1:button1click(tobject *sender)ansistring test=booltostr(checkbox1-checked); /ansistring转 boolvoid _fastcall tform1:button1click(tobject *sender) ansistring test=-1checkbox1-checked= strtobool( test );/int转 ansistringvoid _fastcall tform1:bu

3、tton1click(tobject *sender)int i = 123;ansistring str = inttostr( i );/ansistring转 doublevoid _fastcall tform1:button1click(tobject *sender)ansistring test = 123;long double d = strtofloat( test );/double转 ansistringvoid _fastcall tform1:button1click(tobject *sender)double d = 123.456;ansistring str

4、 = floattostr( d );/double转 ansistring并四舍五入void _fastcall tform1:button1click(tobject *sender)long double d = 123.456121212;ansistring str = floattostrf( d , fffixed ,5 , 4 );/ 说明 floattostrf 里 5 代表从第几个数字的后一位开始四舍五入 ,4 代表取 4 位小数。/ 执行后得到 str 是 123.4600 。:roll:/double 转 ansistring 使用类似 vb 的 format 函数 v

5、oid _fastcall tform1:button1click(tobject *sender)double d = 123.456;ansistring str = formatfloat( 000000.00 , d );/ 得到 000123.45 ,当然你能使用 # . , ; e+ e- xx 等符号,你自己试试 :wink:/ansistring转 tclor 型void _fastcall tform1:button1click(tobject *sender)ansistring test = 0x00ff8080;tcolor col = stringtocolor( t

6、est );/tcolor转 ansistringvoid _fastcall tform1:button1click(tobject *sender)tcolor col = 0x00ff8080;ansistring str = colortostring( col );/ 消除 ansistring 中的一部分字符串 代码 :void _fastcall tform1:button1click(tobject *sender)ansistring test = abcdef;int first = 3;/消除制定开头int length = 2;/消除制定长度ansistring dst

7、r = test.delete( first , length ); / 得到 abef/ 在 ansistring中插入字符串void _fastcall tform1:button1click(tobject *sender)/ 得到ansistring test = abcdef;ansistring ins = 12345;int pos = 3;ansistring istr = test.insert( ins , pos );ab12345cdef/插入串/在哪插/ 取得 ansi 某一位字符void _fastcall tform1:button1click(tobject *

8、sender)ansistring test = abcdef;ansistring npos = test3;/得到c/ 取得 ansistring里最后一个字符void _fastcall tform1:button1click(tobject *sender)ansistring test = abcdef;char *lstr = test.ansilastchar();/得到f/ 取出 ansistring 字符,这个类似 vb 的 mid 函数! void _fastcall tform1:button1click(tobject *sender) ansistring test

9、= abcdef;int first = 3;/ 3开始取int length = 2;/取 2 位/ 得到 cd/ansistring的字母比较void _fastcall tform1:button1click(tobject *sender)ansistring test = abcdef;ansistring sample = abcdef;int result = test.ansicompare( sample );/ 返回 1,不同!分大小写。void _fastcall tform1:button1click(tobject *sender)ansistring test =

10、abcdef;ansistring sample = abcdef;int result = test.ansicompareic( sample );/ 返回 0,相同!没有分大小写,哈哈/ 在 ansistring 中寻找字符void _fastcall tform1:button1click(tobject *sender)ansistring test = abcdef;ansistring sample = e;int result = test.pos( sample );/ 返回 5,如果你写 samplehaha, 就返回 0,未找到,哈哈/ 在 ansistring 中找字符

11、串,和上一个类似void _fastcall tform1:button1click(tobject *sender)ansistring test = abcdef;ansistring sample = ef;int result = test.pos( sample );/ 返回 5,即 e 字符的位置/ 判断字符串长度,类似 vb 的 lenvoid _fastcall tform1:button1click(tobject *sender)ansistring test = 拿金币来 ;int len = test.length();/ 返回 8/ 取得字符串,类似 vb 的 lef

12、tvoid _fastcall tform1:button1click(tobject *sender)ansistring test = 小苹果然看了这篇文章 ;ansistring slstr = test.setlength(6);/ 得到 小苹果 / 检测双字节字串void _fastcall tform1:button1click(tobject *sender)ansistring chkstr = int chkpos =1;你好 ;if ( bytetype( chkstr , chkpos ) = mbsinglebyte ) edit1-text=0;elseedit1-t

13、ext=1;/返回 1,如果你写 chkstr fxxk ,就返回 0/ 检测空字符串void _fastcall tform1:button1click(tobject *sender)ansistring test = ;bool chk = test.isempty();if (chk )edit1-text=1;/返回1/ 全部变小写 vs 全部变大写void _fastcall tform1:button1click(tobject *sender)ansistring test = abcdef;ansistring lstr = test.lowercase();代码 :void

14、 _fastcall tform1:button1click(tobject *sender)ansistring test = abcdef;ansistring ustr = test.uppercase();/ 似 vb 中 trim 的去空格函数void _fastcall tform1:button1click(tobject *sender)ansistring test = abcdef ; ansistring tlstr = test.trimleft();ansistring trstr = test.trimright();ansistring tstr = test.t

15、rim();/ 不 , 个 理不了全角的空格 代 :ansistring _fastcall tform1:trimstr( ansistring tm , ansistring lr )/ lr l:int len;/左除去左除去r: 右除去b:dou除去if ( lr = l | lr = b )len = tm.length();while ( tm.substring(1,1) = | tm.substring(1,2) =)/半角除去if ( tm.substring(1,1) = )tm = tm.substring(2,len);len = tm.length();/全角除去el

16、se if ( tm.substring(1,2) = tm = tm.substring(3,len);len = tm.length(); )/右除去if ( lr = r | lr = b )len = tm.length();while(tm.substring(len,1)tm.substring(len-1,2) = )=|/半角除去if ( tm.substring(len,1) = )len = tm.length();tm = tm.substring(1,len-1);len = tm.length();/全角除去else if ( tm.substring(len-1,2

17、) = len = tm.length();tm = tm.substring(1,len-2);len = tm.length(); )return tm;void _fastcall tform1:button1click(tobject *sender)ansistring test = 拳脚 ansistring ret = trimstr(test,b);/ 相同字符重复输入void _fastcall tform1:button1click(tobject *sender)ansistring soc = ansistring:stringofchar(edit1-text=soc

18、 ;/显示 100 个 * ,100 );/ 字符串替换void _fastcall tform1:button1click(tobject *sender)ansistring str = borland c+ builder is free;ansistringfrom=c+builder;ansistringto=delphi;ansistringresult;result = stringreplace( str, from, to, treplaceflags() rfreplaceall rfignorecase );/text=han;/ 半角变全角void _fastcall tform1:button1click(tobject *sender

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论