会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
编程之美
千人.NET交流群:18362376,因为有你,代码变得更简单
博客园
首页
新随笔
联系
订阅
管理
HTML中字符大小写转换(java)
import
java.io.BufferedReader;
import
java.io.BufferedWriter;
import
java.io.FileInputStream;
import
java.io.FileNotFoundException;
import
java.io.FileWriter;
import
java.io.IOException;
import
java.io.InputStreamReader;
/** */
/**
* 将HTML中< >中的字母大小写进行转换
*
@author
*
*/
public
class
ExchangeCase
{
public
static
void
main(String args[])
throws
IOException
{
boolean
aFlg
=
false
;
//
判斷"<>"用;
int
intCount
=
0
;
//
计算"<>"用;
int
intLine
=
0
;
//
行数
String strCurrentLine
=
null
;
//
当前行
String []dataSave
=
new
String[
10000
];
//
将读到的每一行放进一个数组
try
{
BufferedReader BRead
=
new
BufferedReader(
new
InputStreamReader(
new
FileInputStream(
"
C:/Html.html
"
) ));
//
读取文件
BufferedWriter BWriter
=
new
BufferedWriter(
new
FileWriter(
"
C:/Html2.txt
"
));
//
转成后放到此文件
while
((strCurrentLine
=
BRead.readLine())
!=
null
)
{
dataSave[intLine]
=
strCurrentLine;
intLine
=
intLine
+
1
;
}
//
System.out.println("総行数="+intLine);
for
(
int
i
=
0
; i
<
intLine;i
++
)
{
aFlg
=
false
;
intCount
=
0
;
for
(
int
j
=
0
; j
<
dataSave[i].length(); j
++
)
{
char
cByte
=
dataSave[i].charAt(j);
if
(cByte
==
'
<
'
&&
intCount
==
0
)
{
aFlg
=
true
;
}
if
(cByte
==
'
<
'
)
{
++
intCount;
}
if
(cByte
==
'
>
'
)
{
--
intCount;
}
if
(cByte
==
'
>
'
&&
intCount
==
0
)
{
aFlg
=
false
;
}
if
(aFlg
&&
intCount
>
0
)
{
//
转成小写
if
(cByte
>=
'
A
'
&&
cByte
<=
'
Z
'
)
{
//
大写: cByte >= 'a' && cByte <= 'z'
cByte
+=
32
;
//
大写: cByte -= 32;
//
System.out.print(cByte);
BWriter.write(cByte);
continue
;
}
else
{
//
System.out.print(cByte);
BWriter.write(cByte);
continue
;
}
}
//
System.out.print(cByte);
BWriter.write(cByte);
}
//
System.out.println();
BWriter.newLine();
}
BRead.close();
BWriter.close();
}
catch
(FileNotFoundException e)
{
e.printStackTrace();
}
}
}
千人.NET交流群:18362376,因为有你,代码变得更简单,加群请输入cnblogs
posted @
2008-04-02 11:09
kingkoo
阅读(
3022
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告