軟件藝術思考者  
          混沌,彷徨,立志,蓄勢...
          公告
          日歷
          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導航

          隨筆分類(86)

          隨筆檔案(85)

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

           

           /**
               * 字符串替換,將 source 中的 oldString 全部換成 newString
               *
               * @param source 源字符串
               * @param oldString 老的字符串
               * @param newString 新的字符串
               * @return 替換后的字符串
               */
              public static String replaceStr(String source, String oldString, String newString) {
                  StringBuffer output = new StringBuffer();

                  int lengthOfSource = source.length();   // 源字符串長度
                  int lengthOfOld = oldString.length();   // 老字符串長度

                  int posStart = 0;   // 開始搜索位置
                  int pos;            // 搜索到老字符串的位置

                  while ((pos = source.indexOf(oldString, posStart)) >= 0) {
                      output.append(source.substring(posStart, pos));

                      output.append(newString);
                      posStart = pos + lengthOfOld;
                  }

                  if (posStart < lengthOfSource) {
                      output.append(source.substring(posStart));
                  }

                  return output.toString();
              }
           public static void main(String[] args) {
            System.out.println(replaceIgnoreCase("War is wAr and waR and war","war","[start]","[end]"));
            System.out.println(replaceIgnoreCase("","war","[start]","[end]"));
            System.out.println(replaceIgnoreCase("Warsdf","war","[start]","[end]"));
            System.out.println(replaceIgnoreCase("sdfWar","war","[start]","[end]"));
           }

           /**
            * 2007-7-30 added by lxs
            * 將原有的字符串按照需要的長度顯示,超出的長度用..代替。
            * 給定的長度應包含2位..的長度數。
            */
           /*
            *0x3400->13312->'?' 0x9FFF->40959->? 0xF900->63744->?
            *
            **/
           public static String getPointStr(String str,int length){
            if(str==null || "".equals(str)){
             return "";
            }
            if(getStrLength(str)>length){
             str=getLeftStr(str,length-2);
            }
            return str;
           }

           public static String getLeftStr(String str,int length){
            
            if(str == null || "".equals(str)){
             return "";
            }
            int index = 0;
           
            char[] charArray = str.toCharArray();
            for(;index<length; index++){
             if(((charArray[index]>=0x3400)&&(charArray[index]<0x9FFF))||(charArray[index]>=0xF900)){
              length --;
             }
            }
            String returnStr = str.substring(0, index);
            returnStr += "..";
            return returnStr;
           }
           
           public static int getStrLength(String str){
            if(str==null || "".equals(str)){
             return 0;
            }
            char[] charArray = str.toCharArray();
            int length = 0;
            for(int i = 0; i < charArray.length; i++){
             if(((charArray[i]>=0x3400)&&(charArray[i]<0x9FFF))||(charArray[i]>=0xF900)){
              length += 2;
             }else{
              length ++;
             }
            }
            return length;
           }
           
              /**
               * 將字符串格式化成 HTML 代碼輸出
               * 只轉換特殊字符,適合于 HTML 中的表單區域
               *
               * @param str 要格式化的字符串
               * @return 格式化后的字符串
               */
              public static String toHtmlInput(String str) {
                  if (str == null)    return null;

                  String html = new String(str);
                  //html = replaceStr(html, "<", "&lt;");
                  //html = replaceStr(html, ">", "&gt;");
                  html = replaceStr(html, "\r\n", "<br>");
                  //html = replaceStr(html, "\n", "<br>");
                  //html = replaceStr(html, "&", "&amp;");
                  html = replaceStr(html, "\t", "    ");
                  html = replaceStr(html, " ", "&nbsp;");
                  return html;
              }
              public static String toHtmlInputExceptSpace(String str) {
                  if (str == null)    return null;

                  String html = new String(str);
                  html = replaceStr(html, "<", "&lt;");
                  html = replaceStr(html, ">", "&gt;");
                  html = replaceStr(html, "\r\n", "\n");
                  html = replaceStr(html, "\n", "<br>\n");
                  html = replaceStr(html, "&", "&amp;");
                  html = replaceStr(html, "\t", "    ");
                  return html;
              }

              public static String toHtmlOutput(String str) {
               if (str == null)    return null;
           
               String html = new String(str);
                  html = replaceStr(html, "<br>\n", "\n");
               html = replaceStr(html, "&amp;", "&");
               html = replaceStr(html, "&lt;", "<");
               html = replaceStr(html, "&gt;", ">");
                  html = replaceStr(html, "\n", "\r\n");
                  html = replaceStr(html, "    ", "\t");
                  html = replaceStr(html, " ", " ");
                 
           
               return html;
              }
             
              public static String toHtmlOutput1(String str) {
               if (str == null)    return null;
           
               String html = new String(str);
                  html = replaceStr(html, "<br>\n", "\n");
               html = replaceStr(html, "&amp;", "&");
               html = replaceStr(html, "&lt;", "<");
               html = replaceStr(html, "&gt;", ">");
                  //html = replaceStr(html, "\n", "\r\n");
                  html = replaceStr(html, "    ", "\t");
                  html = replaceStr(html, " ", " ");
                 
           
               return html;
              }

          posted on 2007-09-20 16:29 智者無疆 閱讀(1405) 評論(12)  編輯  收藏 所屬分類: about java
          評論:
          • # re: JAVA STRING UTIL[未登錄]  lijun Posted @ 2007-09-24 16:29
            hosts的位置:C:\WINDOWS\system32\drivers\etc\hosts  回復  更多評論   

          • # re: JAVA STRING UTIL[未登錄]  lijun Posted @ 2007-09-26 10:34
            java全文檢索
            http://www-128.ibm.com/developerworks/cn/java/j-lo-lucene1/  回復  更多評論   

          • # re: JAVA STRING UTIL[未登錄]  lijun Posted @ 2007-09-29 14:25
            //截取字符串
            public static String substring(String str, int byteNumber) {
            int reInt = 0;
            String reStr = "";
            if (str == null) return "";
            char[] tempChar = str.toCharArray();
            for (int kk = 0; (kk < tempChar.length && byteNumber > reInt); kk++) {
            String s1 = str.valueOf(tempChar[kk]);
            byte[] b = s1.getBytes();
            reInt += b.length;
            reStr += tempChar[kk];
            }

            return reStr;
            }  回復  更多評論   

          • # re: JAVA 快速排序[未登錄]  lijun Posted @ 2007-12-12 17:37
            Comparator<HashMap> objComer=new Comparator<HashMap>(){
            public int compare(HashMap a,HashMap b){
            if(a.get("endTime")==null||b.get("endTime")==null)return 1;
            else return ((Date)a.get("endTime")).compareTo((Date)b.get("endTime"));
            }
            };
            Collections.sort(list,Collections.reverseOrder(objComer) );  回復  更多評論   

          • # re: JAVA File UTIL  智者無疆 Posted @ 2008-01-10 14:38
            package com.wonibo.projectx.util;

            import java.io.BufferedReader;
            import java.io.BufferedWriter;
            import java.io.File;
            import java.io.FileInputStream;
            import java.io.FileOutputStream;
            import java.io.FileReader;
            import java.io.FileWriter;
            import java.io.InputStream;
            import java.io.PrintWriter;
            import java.util.Locale;
            import java.util.ResourceBundle;
            import java.util.regex.Matcher;
            import java.util.regex.Pattern;
            import java.util.Locale;
            import java.util.ResourceBundle;

            public class FileUtil {
            /*
            *?????????
            */
            /*public static void depthFirst(File root){
            System.out.println(root);
            File subroots[]=root.listFiles(new FileFilter(){
            public boolean accept(File pathname) {
            return pathname.isDirectory();
            }
            });
            if(subroots!=null){
            for(int i=0;i<subroots.length;i++){
            depthFirst(subroots[i]);
            }
            }
            }
            */


            /**
            * ?½??¼
            * @param folderPath String ?? c:/fqf
            * @return boolean
            */
            public static boolean newFolder(String folderPath) {
            try {
            String filePath = folderPath;
            filePath = filePath.toString();
            File myFilePath = new File(filePath);
            if (!myFilePath.exists()) {
            myFilePath.mkdir();
            }
            return true;
            }
            catch (Exception ex) {
            ex.printStackTrace();
            return false;
            }
            }

            /**
            * ?½????
            * @param filePathAndName String ???·??????? ??c:/fqf.txt
            * @param fileContent String ???????
            * @return boolean
            */
            public static boolean newFile(String filePathAndName, String fileContent) {

            try {
            String filePath = filePathAndName;
            filePath = filePath.toString();
            File myFilePath = new File(filePath);
            if (!myFilePath.exists()) {
            myFilePath.createNewFile();
            }
            FileWriter resultFile = new FileWriter(myFilePath);
            PrintWriter myFile = new PrintWriter(resultFile);
            String strContent = fileContent;
            myFile.println(strContent);
            myFile.close();
            resultFile.close();
            return true;
            }
            catch (Exception ex) {
            ex.printStackTrace();
            return false;
            }
            }

            public static void makeDir(String path){
            try{
            String tmp[]=StringUtil.splitStr(path,'/');
            path=tmp[0];
            for(int i=1;i<tmp.length;i++){
            path+="/"+tmp[i];
            FileUtil.newFolder(path);
            }
            }catch(Exception ex){
            ex.printStackTrace();
            }

            }

            /* ???????д???
            * @return boolean
            */
            public static void writeLine(String filePathAndName, String fileContent) {
            try {
            String filePath = filePathAndName;
            filePath = filePath.toString();
            File myFilePath = new File(filePath);
            if (!myFilePath.exists()) {
            myFilePath.createNewFile();
            }
            if(myFilePath.canWrite()){
            FileWriter resultFile = new FileWriter(myFilePath,true);
            BufferedWriter myFile = new BufferedWriter(resultFile);
            String strContent = fileContent;
            myFile.newLine();
            myFile.write(strContent);
            myFile.newLine();
            myFile.write("----------------------------------------");
            myFile.close();
            resultFile.close();
            }
            }
            catch (Exception ex) {
            ex.printStackTrace();
            }
            }
            public static void writeLineNew(String filePathAndName, String fileContent) {
            try {
            String filePath = filePathAndName;
            filePath = filePath.toString();
            File myFilePath = new File(filePath);
            if (!myFilePath.exists()) {
            myFilePath.createNewFile();
            }
            if(myFilePath.canWrite()){
            FileWriter resultFile = new FileWriter(myFilePath,true);
            BufferedWriter myFile = new BufferedWriter(resultFile);
            String strContent = fileContent;
            myFile.newLine();
            myFile.write(strContent);
            myFile.newLine();
            myFile.write("----------------------------------------");
            myFile.close();
            resultFile.close();
            }
            }
            catch (Exception ex) {
            ex.printStackTrace();
            }
            }
            /**
            * ??????
            * @param filePathAndName String ???·??????? ??c:/fqf.txt
            * @param fileContent String
            * @return boolean
            */
            public static boolean delFile(String filePathAndName) {
            try {
            String filePath = filePathAndName;
            filePath = filePath.toString();
            java.io.File myDelFile = new java.io.File(filePath);
            myDelFile.delete();
            return true;
            }
            catch (Exception ex) {
            ex.printStackTrace();
            return false;
            }
            }

            /**
            * ????????
            * @param filePathAndName String ?????·??????? ??c:/fqf
            * @param fileContent String
            * @return boolean
            */
            public static void delFolder(String folderPath) {
            try {
            delAllFile(folderPath); //?????????????????
            String filePath = folderPath;
            filePath = filePath.toString();
            java.io.File myFilePath = new java.io.File(filePath);
            myFilePath.delete(); //?????????

            }
            catch (Exception ex) {
            ex.printStackTrace();
            }

            }

            /**
            * ????????????????????
            * @param path String ?????·?? ?? c:/fqf
            */
            public static void delAllFile(String path) {
            File file = new File(path);
            if (!file.exists()) {
            return;
            }
            if (!file.isDirectory()) {
            return;
            }
            String[] tempList = file.list();
            File temp = null;
            for (int i = 0; i < tempList.length; i++) {
            if (path.endsWith(File.separator)) {
            temp = new File(path + tempList[i]);
            }
            else {
            temp = new File(path + File.separator + tempList[i]);
            }
            if (temp.isFile()) {
            temp.delete();
            }
            if (temp.isDirectory()) {
            delAllFile(path+"/"+ tempList[i]);//??????????????????
            delFolder(path+"/"+ tempList[i]);//???????????
            }
            }
            }

            /**
            * ??????????
            * @param oldPath String ????·?? ?磺c:/fqf.txt
            * @param newPath String ?????·?? ?磺f:/fqf.txt
            * @return boolean
            */
            public static void copyFile(String oldPath, String newPath) {
            try {

            File oldfile = new File(oldPath);
            if (oldfile.exists()) { //????????
            InputStream inStream = new FileInputStream(oldPath); //????????
            FileOutputStream fs = new FileOutputStream(newPath);
            byte[] buffer = new byte[1024];
            while (inStream.read(buffer) != -1) {
            fs.write(buffer);
            }
            fs.close();
            inStream.close();
            }
            }
            catch (Exception ex) {
            //System.out.println("copy error");
            ex.printStackTrace();
            }

            }

            /**
            * ????????????????
            * @param oldPath String ????·?? ?磺c:/fqf
            * @param newPath String ?????·?? ?磺f:/fqf/ff
            * @return boolean
            */
            public static boolean copyFolder(String oldPath, String newPath) {

            try {
            (new File(newPath)).mkdirs(); //???????в????? ??b???????
            File a=new File(oldPath);
            String[] file=a.list();
            File temp=null;
            for (int i = 0; i < file.length; i++) {
            if(oldPath.endsWith(File.separator)){
            temp=new File(oldPath+file[i]);
            }
            else{
            temp=new File(oldPath+File.separator+file[i]);
            }

            if(temp.isFile()){
            FileInputStream input = new FileInputStream(temp);
            FileOutputStream output = new FileOutputStream(newPath + "/" +
            (temp.getName()).toString());
            byte[] b = new byte[1024 * 5];
            int len;
            while ( (len = input.read(b)) != -1) {
            output.write(b, 0, len);
            }
            output.flush();
            output.close();
            input.close();
            }
            if(temp.isDirectory()){//????????????
            copyFolder(oldPath+"/"+file[i],newPath+"/"+file[i]);
            }
            }
            return true;
            }
            catch (Exception ex) {
            ex.printStackTrace();
            return false;
            }
            }

            /**
            * ????????????¼
            * @param oldPath String ?磺c:/fqf.txt
            * @param newPath String ?磺d:/fqf.txt
            */
            public static void moveFile(String oldPath, String newPath) {
            copyFile(oldPath, newPath);
            delFile(oldPath);

            }

            /**
            * ????????????¼
            * @param oldPath String ?磺c:/fqf.txt
            * @param newPath String ?磺d:/fqf.txt
            */
            public static void moveFolder(String oldPath, String newPath) {
            copyFolder(oldPath, newPath);
            delFolder(oldPath);
            }

            /**
            * ??????????
            */
            public static String readFile(String filePathAndName){
            try {
            String filePath = filePathAndName;
            filePath = filePath.toString();
            String content=null;
            String tmp=null;
            File myFilePath = new File(filePath);
            if (myFilePath.exists()) {
            FileReader fr=new FileReader(myFilePath);
            BufferedReader br=new BufferedReader(fr);
            content=new String();
            tmp=new String();
            while((tmp=br.readLine())!=null){
            content=content+tmp;
            }
            br.close();
            fr.close();
            }
            return content;
            }
            catch (Exception ex) {
            ex.printStackTrace();
            return null;
            }
            }

            public static boolean ifFileExists(String filePathAndName){
            try{
            File myFilePath = new File(filePathAndName);
            if (myFilePath.exists()) {
            return true;
            }else{
            return false;
            }
            }catch(Exception ex){
            ex.printStackTrace();
            return false;
            }
            }


            public static String[] getFileList(String path){
            File dir=new File(path);
            String[] files=dir.list();
            return files;
            }

            public static String getRandFileName(){
            return ((Long)System.currentTimeMillis()).toString();
            }
            public static long getFileSize(String pathandname){
            File file=new File(pathandname);
            long temp=file.length();
            return temp;
            }



            public static ResourceBundle getResourceBundle(String bundleName,String language){
            String country;
            if(language.equals("zh")) country="CN";
            else if(language.equals("en")) country="US";
            else if(language.equals("ja")) country="JP";
            else country="";
            Locale currentLocale;
            ResourceBundle messages;
            currentLocale = new Locale(language, country);
            messages = ResourceBundle.getBundle(bundleName,currentLocale);
            return messages;
            }

            public static void main(String[] args) {
            ResourceBundle message=getResourceBundle("resources.test","ja");
            System.out.println(message.getString("index.title"));
            message=getResourceBundle("resources.test","en");
            System.out.println(message.getString("index.title"));
            message=getResourceBundle("resources.test","zh");
            System.out.println(message.getString("index.title"));
            }
            }
              回復  更多評論   

          • # re: 過濾jsp頁面中引用的所有js[未登錄]  lijun Posted @ 2008-01-22 10:36
            <servlet-mapping>
            <servlet-name>jsp</servlet-name>
            <url-pattern>*.js</url-pattern>
            </servlet-mapping>   回復  更多評論   

          • # re: 過濾jsp頁面中引用的所有js[未登錄]  lijun Posted @ 2008-01-22 10:36
            以上在web.xml里配置  回復  更多評論   

          • # re: web.xml里配置session的失效期[未登錄]  lijun Posted @ 2008-01-22 10:37
            <session-config>
            <session-timeout>60</session-timeout>
            </session-config>  回復  更多評論   

          • # re: web.xml里配置filter[未登錄]  lijun Posted @ 2008-01-22 10:39
            <filter>
            <filter-name>logincheckfilter</filter-name>
            <filter-class>com.wonibo.projectx.web.servlet.LoginFilter</filter-class>
            </filter>
            <filter-mapping>
            <filter-name>logincheckfilter</filter-name>
            <url-pattern>*.jsp</url-pattern>
            </filter-mapping>
            <filter-mapping>
            <filter-name>logincheckfilter</filter-name>
            <url-pattern>/admin/*</url-pattern>
            </filter-mapping>
            <filter-mapping>
            <filter-name>logincheckfilter</filter-name>
            <url-pattern>/app/*</url-pattern>
            </filter-mapping>
            <filter-mapping>
            <filter-name>logincheckfilter</filter-name>
            <url-pattern>/jsp_cn/*</url-pattern>
            </filter-mapping>
            public class LoginFilter extends HttpServlet implements Filter {
            /**
            *
            */
            private static final long serialVersionUID = 1L;
            private FilterConfig filterConfig;
            //Handle the passed-in FilterConfig
            public void init(FilterConfig filterConfig) throws ServletException {
            this.filterConfig = filterConfig;
            }
            public void destroy() {

            }

            public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain filterChain) {
            try {
            //?????????????????????
            HttpServletRequest httpRequest = (HttpServletRequest) request;
            HttpServletResponse httpResponse = (HttpServletResponse) response;
            //HttpSessionContext SessCon= httpRequest.getSession().getSessionContext();
            //HttpSession Sess = SessCon.getSession("");
            UserInfo_Home userInfoHome=(UserInfo_Home)httpRequest.getSession().getAttribute("userInfoHome");
            if(userInfoHome==null){
            ApplicationContext applicationContext=WebApplicationContextUtils.getRequiredWebApplicationContext(filterConfig.getServletContext());
            UserService userService =(UserService)applicationContext.getBean("userServiceManager");
            //userService.checkCookie(httpRequest);
            userInfoHome=userService.getFlexUserLogin(httpRequest);
            //????û?????¼???
            if(userInfoHome!=null){
            WbUser wbUser=userService.getUserInfoById(userInfoHome.getUser_id());
            Date lastLoginDate=new Date(System.currentTimeMillis());
            wbUser.setLastLoginTimeMedia(wbUser.getLastLoginDate());
            wbUser.setLastLoginDate(lastLoginDate);
            userService.updateWbUser(wbUser);
            }
            //**************end
            httpRequest.getSession().setAttribute("userInfoHome",userInfoHome);
            }

            //***********************************  回復  更多評論   

          • # spring 的quartz定時調度[未登錄]  lijun Posted @ 2008-02-13 09:31
            <!-- *********************定時任務開始**************************************** -->
            <!-- 要調用的工作類 -->
            <bean id="quartzJob" class="cn.com.swjay.guidelineconfig.service.model.impl.JobServiceImpl"></bean>
            <!-- 定義調用對象和調用對象的方法 -->
            <bean id="jobtask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
            <!-- 調用的類 -->
            <property name="targetObject">
            <ref bean="quartzJob"/>
            </property>
            <!-- 調用類中的方法 -->
            <property name="targetMethod">
            <value>work</value>
            </property>
            </bean>
            <!-- 定義觸發時間 -->
            <bean id="doTime" class="org.springframework.scheduling.quartz.CronTriggerBean">
            <property name="jobDetail">
            <ref bean="jobtask"/>
            </property>
            <!-- cron表達式 -->
            <property name="cronExpression">
            <value>10,15,20,25,30,35,40,45,50,55 * * * * ?</value>
            </property>
            </bean>
            <!-- 總管理類 如果將lazy-init='false'那么容器啟動就會執行調度程序 -->
            <!--bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
            <property name="triggers">
            <list>
            <ref bean="doTime"/>
            </list>
            </property>
            </bean-->
            <!-- *********************定時任務結束**************************************** -->  回復  更多評論   

          • # re: JAVA 驗證碼及使用[未登錄]  lijun Posted @ 2008-03-20 16:34
            image.jsp
            <%@ page contentType="image/jpeg" import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*" %><%!
            Color getRandColor(int fc,int bc){
            Random random = new Random();
            if(fc>255) fc=255;
            if(bc>255) bc=255;
            int r=fc+random.nextInt(bc-fc);
            int g=fc+random.nextInt(bc-fc);
            int b=fc+random.nextInt(bc-fc);
            return new Color(r,g,b);
            }
            %><%
            response.setHeader("Pragma","No-cache");
            response.setHeader("Cache-Control","no-cache");
            response.setDateHeader("Expires", 0);

            int width=60, height=20;
            BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

            Graphics g = image.getGraphics();

            Random random = new Random();

            g.setColor(getRandColor(200,250));
            g.fillRect(0, 0, width, height);

            g.setFont(new Font("Times New Roman",Font.PLAIN,18));

            g.setColor(getRandColor(160,200));
            for (int i=0;i<155;i++)
            {
            int x = random.nextInt(width);
            int y = random.nextInt(height);
            int xl = random.nextInt(12);
            int yl = random.nextInt(12);
            g.drawLine(x,y,x+xl,y+yl);
            }

            String sRand="";
            for (int i=0;i<4;i++){
            String rand=String.valueOf(random.nextInt(10));
            sRand+=rand;
            g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));
            g.drawString(rand,13*i+6,16);
            }

            //session.setAttribute("commentrand",sRand);
            //String str = new String(request.getParameter("test").getBytes("ISO8859_1"));
            String str = new String(request.getParameter("sessname").getBytes("ISO8859_1"));
            session.setAttribute(str,sRand);
            //System.out.println("sessname:"+str+"="+sRand);
            g.dispose();

            ImageIO.write(image, "JPEG", response.getOutputStream());
            %>
            2.使用的頁面


            function show(o,va){

            //重載驗證碼
            var path='<%=contextPath%>';
            //alert(path);
            var timenow=new Date().getTime();
            o.src=path+"/img/image.jsp?sessname="+va+"&d="+timenow;
            /*
            //超時執行;
            setTimeout(function(){o.src="random.jsp?sessname="+va+"&d="+timenow;},20);
            */

            }

            <tr>
            <td align="left" height="30"><ww:text name="spacehome.verycode">驗證碼:</ww:text>:</td>
            <td align="left"><input type="text" name="randCode" maxlength=4 class="guestbookinputma input" /> <img border=0 id="random" src="<%=contextPath%>/img/image.jsp?sessname=${sessionName}"/> <a href="javascript:show(document.getElementById('random'),'${sessionName}')"><ww:text name="spacehome.verynosee">看不清楚?換一個</ww:text></a></td>
            </tr>
              回復  更多評論   

          • # 判斷是不是漢字[未登錄]  lijun Posted @ 2008-03-31 11:03
            public static void main(String[] args) {
            String str = "我lu是ya一個ng貓";
            char[] arr = str.toCharArray();
            for (int i = 0; i < arr.length; i++) {
            if (String.valueOf(arr[i]).matches("[\\u4e00-\\u9fa5]")) {
            System.out.println("字符 \\"" + arr[i] + " \\"是" + "漢字");
            } else {

            System.out.println("字符 \\"" + arr[i] + " \\"是" + "字母");
            }
            }
            }
            這樣就OK了。  回復  更多評論   

           
          Copyright © 智者無疆 Powered by: 博客園 模板提供:滬江博客


             觀音菩薩贊

          主站蜘蛛池模板: 三穗县| 容城县| 新巴尔虎右旗| 逊克县| 尚义县| 文山县| 长海县| 鱼台县| 定西市| 比如县| 开阳县| 无棣县| 教育| 繁峙县| 左权县| 金昌市| 瓮安县| 忻州市| 绥阳县| 中阳县| 蒙山县| 阿巴嘎旗| 夹江县| 怀安县| 建湖县| 万盛区| 仁布县| 嵩明县| 彩票| 民丰县| 翼城县| 凉山| 刚察县| 察雅县| 大邑县| 桦南县| 深州市| 营山县| 许昌县| 甘德县| 西华县|