标签:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
const S1: ShortString = ‘Hello World‘ ; var X: Integer ; SP: PChar ; S2: string ; RS: string ; { 显示最后的结果} begin SP := ‘Pchar‘ ; //copy函数获取从最后一个字符开始,共一个字符 S2 := Copy(S1, Length(S1), 1 ); { S2 = ‘d‘} RS := RS + S2 + # 13 # 10 ; //删除字符串中指定位置字符的Delete函数 S2 := S1; Delete(S2, 1 , 1 ); { S2 = ‘ello World‘} RS := RS + S2 + # 13 # 10 ; //格式化字符串Format函数 S2 := Format( ‘Time is : %d:%d:%d‘ , [ 12 , 15 , 40 ]); { S2 = ‘Time is : 12:15:40‘} {%d表示将在这里放置一个整数,[2011]表示放置2011这个数值} RS := RS + S2 + # 13 # 10 ; //数值转换为字符串InttoStr函数 X := 65535 ; S2 := IntToStr(X); { S2 = ‘10‘} RS := RS + S2 + # 13 # 10 ; //获取字符串长度Length函数 X := Ord(S1[ 0 ]); { X = 11} X := Length(S1); { 因为S1为ShortString类型,所以可以通过S1[0]来获取字符长度} RS := RS + IntToStr(X) + # 13 # 10 ; //转化为小写LowerCase函数 S2 := LowerCase(S1); { S2 = ‘hello world‘} RS := RS + S2 + # 13 # 10 ; //转化为大写UpperCase函数 S2 := UpperCase(S1); { S2 = ‘HELLO WORLD‘} RS := RS + S2 + # 13 # 10 ; //返回指定字符重复的字符串 S2 := StringOfChar( ‘A‘ , 10 ); { S2 = ‘AAAAAAAAAA‘} RS := RS + S2 + # 13 # 10 ; //StrPas把一个空结尾字符串(PChar或字符数组)转化为Pascal字符串 S2 := StrPas(SP); { S2 = ‘Pchar‘} RS := RS + S2 + # 13 # 10 ; //StrPCopy把一个Pascal字符串转化为空结尾字符串 StrPCopy(SP, ‘World Hello‘ ); { SP = ‘World Hello‘} RS := RS + StrPas(SP) + # 13 # 10 ; //Trim用于去除字符串前后的空格和控制字符 S2 := # 13 # 10 ‘ Hello World ‘ ; S2 := Trim(S2); { S2 = ‘Hello World‘} RS := RS + S2 + # 13 # 10 ; //StringReplace用于替换字符串中制定字符 S2 := ‘AABBCC‘ ; S2 := StringReplace(S2, ‘A‘ , ‘E‘ , [rfReplaceAll]); RS := RS + S2 + # 13 # 10 ; ShowMessage(RS); end ; |
标签:
原文地址:http://www.cnblogs.com/BillLei/p/4286041.html