VB API 第二课 之 字符串大小写转换

直接上代码解释更加清楚

//说明:本实例用到4个API函数CharLower,CharLowerBuff,CharUpper,CharUpperBuff,分别是对字符串进行大小写转换。进行每个字符串大小写转换。

用到4个按钮,2个编辑框控件2个标签控件。

Option Explicit

Private Declare Function CharLower Lib "user32" Alias "CharLowerA" (ByVal lpsz As String) As String

Private Declare Function CharLowerBuff Lib "user32" Alias "CharLowerBuffA" (ByVal lpsz As String, ByVal cchLength As Long) As Long

Private Declare Function CharUpper Lib "user32" Alias "CharUpperA" (ByVal lpsz As String) As String

Private Declare Function CharUpperBuff Lib "user32" Alias "CharUpperBuffA" (ByVal lpsz As String, ByVal cchLength As Long) As Long

Dim c1 As Integer '大写的字符的个数
Dim c2 As Integer '小写的字符的个数
Dim s1 As String '字符串

Private Sub Command1_Click()
Text2.Text = CharUpper(Text1.Text) '字符串全部转换大写
c2 = 0 '小写的字符个数就为0

End Sub

Private Sub Command2_Click()
Text2.Text = CharLower(Text1.Text) '字符串全部转换小写
c1 = 0 '大写字符的个数为0
End Sub

Private Sub Command3_Click()
If c1 < Len(Text1.Text) Then '如果大写的字符个数小于编辑框字符的个数
c1 = c1 + 1 '大写的字符个数加1
c2 = Len(Text1.Text) - c1 '小写的个数就减一
Else
MsgBox "全部字符转换完毕!"
Exit Sub
End If
s1 = Text1.Text '已转换大写编辑框1的字符串赋值给s1
CharUpperBuff s1, c1 '第一个参数表示要转换的字符串,大写字符的个数
Text2.Text = s1 's1赋值给编辑框2的内容

End Sub

Private Sub Command4_Click() '同上
If c2 < Len(Text1.Text) Then
c2 = c2 + 1
c1 = Len(Text1.Text) - c2
Else
MsgBox "全部字符转换完毕!"
Exit Sub
End If
s1 = Text2.Text
CharLowerBuff s1, c2
Text2.Text = s1

End Sub

Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
c1 = 0
c2 = 0

End Sub

 如图所示:

下节课字体函数的应用

转载于:https://www.cnblogs.com/delphi2014/p/4007046.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值