软件艺术思考者  
混沌,彷徨,立志,蓄势...
公告
日历
<2024年11月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
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 智者无疆 阅读(1393) 评论(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: 博客园 模板提供:沪江博客


   观音菩萨赞