Android Open Source - CommonLibs String Utils






From Project

Back to project page CommonLibs.

License

The source code is released under:

Apache License

If you think the Android project CommonLibs listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.alex.common.utils;
/*from  w  w  w  .ja va2s  .co m*/
import java.util.Calendar;
import java.util.Date;

import android.text.TextUtils;

/**
 * ???????
 * @author caisenchuan
 */
public class StringUtils {
    /*--------------------------
     * ???
     *-------------------------*/

    /*--------------------------
     * ?????
     *-------------------------*/

    /*--------------------------
     * ????????
     *-------------------------*/

    /*--------------------------
     * public??
     *-------------------------*/
    /**
     * ????????????????,???????,?????
     * @param date - ???????
     * @return ?????
     * @author caisenchuan
     **/
    public static String getDateString(Date date) {
        Calendar c_t = Calendar.getInstance();
        c_t.setTime(date);
        int y_t = c_t.get(Calendar.YEAR);
        int m_t = c_t.get(Calendar.MONTH) + 1;
        int d_t = c_t.get(Calendar.DAY_OF_MONTH);
        int h_t = c_t.get(Calendar.HOUR_OF_DAY);
        int mi_t = c_t.get(Calendar.MINUTE);
        
        Calendar c_now = Calendar.getInstance();
        int y_now = c_now.get(Calendar.YEAR);
        int m_now = c_now.get(Calendar.MONTH) + 1;
        int d_now = c_now.get(Calendar.DAY_OF_MONTH);
        int h_now = c_now.get(Calendar.HOUR_OF_DAY);
        int mi_now = c_now.get(Calendar.MINUTE);
        
        System.out.println(String.format("%s %s %s %s %s", y_t, m_t, d_t, h_t, mi_t));
        System.out.println(String.format("%s %s %s %s %s", y_now, m_now, d_now, h_now, mi_now));
        
        String ret = String.format("%s?%s?%s?", y_t, m_t, d_t);
        int diff = 0;
        if(c_t.after(c_now)) {
            //?????????
        } else if(y_t < y_now) {
            //???????
        } else if(m_t < m_now) {
            //????
            ret = String.format("%s?%s?", m_t, d_t);
        } else if(d_t < d_now) {
            //X???
            diff = d_now - d_t;
            if(diff == 1) {
                ret = "??";
            } else {
                ret = diff + "???";
            }
        } else if(h_t < h_now) {
            //X?????
            diff = h_now - h_t;
            ret = diff + "?????";
        } else if(mi_t < mi_now) {
            //X????
            diff = mi_now - mi_t;
            ret = diff + "????";
        } else {
            ret = "??";
        }
        
        return ret;
    }
    
    /**
     * ??????????
     * @param text
     * @return
     * @author caisenchuan
     */
    public static String getStripContent(String text) {
        String ret = "";
        
        if(!TextUtils.isEmpty(text)) {
            int i = text.indexOf("????");
            if(i > 0) {
                ret = text.substring(0, i);
            }
        }
        
        return ret;
    }
    
    /**
     * ???????????
     * @param url
     * @return
     */
    public static boolean isLocalUri(String url) {
        boolean ret = false;
        
        if(url != null && 
           (url.startsWith("file://") || url.startsWith("/"))) {
            ret = true;
        }
        
        return ret;
    }
    /*--------------------------
     * protected??packet??
     *-------------------------*/

    /*--------------------------
     * private??
     *-------------------------*/

}




Java Source Code List

com.alex.common.AppConfig.java
com.alex.common.AppControl.java
com.alex.common.Err.java
com.alex.common.OnHttpRequestReturnListener.java
com.alex.common.activities.BaseActivity.java
com.alex.common.activities.ImageLoadActivity.java
com.alex.common.activities.WebViewActivity.java
com.alex.common.apis.HttpApi.java
com.alex.common.exception.RetErrorException.java
com.alex.common.utils.BackgroundHandler.java
com.alex.common.utils.BaiduMapUtils.java
com.alex.common.utils.DateTimeUtils.java
com.alex.common.utils.DeviceUtils.java
com.alex.common.utils.DialogUtils.java
com.alex.common.utils.FileUtils.java
com.alex.common.utils.ImageUtils.java
com.alex.common.utils.KLog.java
com.alex.common.utils.Misc.java
com.alex.common.utils.NetworkUtils.java
com.alex.common.utils.PrefUtils.java
com.alex.common.utils.ShareUtils.java
com.alex.common.utils.StringUtils.java
com.alex.common.utils.ThreadUtils.java
com.alex.common.utils.ToastUtils.java
com.alex.common.views.ZoomImageView.java