以下代码字母大小写互换 :
string
str
=
"
ABCabc
"
;
MatchCollection MC
=
Regex.Matches(str,
"
[a-z]
"
);
MatchCollection MC2
=
Regex.Matches(str,
"
[A-Z]
"
);
Encoding encode
=
Encoding.Unicode;
byte
[] SelectedBuffer
=
encode.GetBytes(str);
foreach
(Match M
in
MC)
{
byte
[] UBuffer
=
encode.GetBytes(M.Value.ToUpper());
Array.Copy(UBuffer,
0
, SelectedBuffer, M.Index
<<
1
, UBuffer.Length);
}
foreach
(Match M
in
MC2)
{
byte
[] UBuffer
=
encode.GetBytes(M.Value.ToLower());
Array.Copy(UBuffer,
0
, SelectedBuffer, M.Index
<<
1
, UBuffer.Length);
}
str
=
encode.GetString(SelectedBuffer);