有这样一个字符串,例如:
CA DA ZA YA SA BA HS KA LS MA NS QA TS XA UA EA WA VA GA
现在要转换成如下格式:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
- - A A A - A S - - A S A S - - A - A S A A A A A A
即:将每两位的第一个字母从A到Z按顺序排列在第一行,
第二个字母分别与第一个字母的位置上下对应,如果第一个字母在原字符串中未出现,如A
则在第二行上用 - 与之相对应
请问该如何编程实现(变量可自定义,最好说明一下),谢谢
CA DA ZA YA SA BA HS KA LS MA NS QA TS XA UA EA WA VA GA
现在要转换成如下格式:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
- - A A A - A S - - A S A S - - A - A S A A A A A A
即:将每两位的第一个字母从A到Z按顺序排列在第一行,
第二个字母分别与第一个字母的位置上下对应,如果第一个字母在原字符串中未出现,如A
则在第二行上用 - 与之相对应
请问该如何编程实现(变量可自定义,最好说明一下),谢谢
一个for循环来判断,就可以了
dim strX() as string
dim i as integer,j as integer
dim TempStr as string
str1="CA DA ZA YA SA BA HS KA LS MA NS QA TS XA UA EA WA VA GA"
strX=split(str1," ")
for i=0 to ubound(strX)-1
for j=i+1 to ubound(strX)
if strX(i)>strX(j) then
TempStr=strX(i)
strX(i)=strX(j)
strX(j)=TempStr
end if
next
next
print
for i=0 to ubound(strX)
print left(strX(i),1);
next
print
for i=0 to ubound(strX)
print right(strX(i),1);
next
Text1.Text = StringDismantle("CA DA ZA YA SA BA HS KA LS MA NS QA TS XA UA EA WA VA GA")
End SubFunction StringDismantle(ByVal pString As String) As String
'必须输入AB AB AB AB AB这样的格式,多出一个或者少一个字会导致错误。
Dim tOutString As String
Dim tOutBytes() As Byte '输出标志表数组
ReDim tOutBytes(103) '103=26个字母*4Byte-1
Dim tBytes() As Byte '输入字符串数组
Dim tBytes_Length As Long '输入字符串数组长度(以0开始的)
tBytes() = pString
tBytes_Length = UBound(tBytes)
Dim tBytes_Index As Long '输入字节数组索引
Dim tOutBytes_Index As Long '输出字节数组索引
Dim tOutBytes_Index_Check As Boolean '输出索引检测
Dim tBytesValueL As Long '底位
Dim tBytesValueH As Long '高位
'输出字节初始化
For tOutBytes_Index = 0 To 103 Step 4
tOutBytes(tOutBytes_Index) = 45
tOutBytes(tOutBytes_Index + 2) = 32
Next
'输出字节计算(定位算法)
For tBytes_Index = 0 To tBytes_Length Step 6
tBytesValueH = tBytes(tBytes_Index)
tBytesValueL = tBytes(tBytes_Index + 2)
tOutBytes_Index = (tBytesValueH - 65) * 4
tOutBytes_Index_Check = (tOutBytes_Index >= 0) And (tOutBytes_Index < 104)
If tOutBytes_Index_Check Then
tOutBytes(tOutBytes_Index) = tBytesValueL
End If
Next
tOutString = tOutBytes()
tOutString = "A B C D E F G H I J K L M N O P Q R E T U V W X Y Z" & vbCrLf & tOutString
StringDismantle = tOutString
End Function