• 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();
            }

        }

     
    }

  • 相关阅读:
    vim常用命令
    MYSQL用户管理
    RPM 命令
    Windows下使用xShell向远程Linux上传文件
    Linux PHP 安装过程出现的错误
    完整的 http 错误代码含义解释
    Linux gzip压缩输出
    高性能Mysql主从架构的复制原理及配置详解
    Mybatis多个参数传值方法
    jsp 九大内置对象和其作用详解
  • 原文地址:https://www.cnblogs.com/kingkoo/p/1134205.html
Copyright © 2020-2023  润新知