⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 convertstring.java

📁 java 字符处理
💻 JAVA
字号:
package com.publicclass;

import java.util.*;
import java.lang.*;
import java.io.*;

import com.db.*;

public class convertstring
{
	public static String ConvString(String source_str)
	{
		String target_str;
		
		if (source_str==null || source_str=="")
		{
			target_str="";
		}
		else
		{
			target_str=DBUtil.escapeDBString(source_str);
		}
		return target_str.toString(); 
	}

	public static String ConvertNull(String source_string)
	{
		String target_string;
		
		if (source_string==null || source_string.equals("") || source_string.equals("null") )
		{
			target_string="";
		}
		else
		{
			target_string=source_string;
		}
		return target_string.toString(); 
	}
	public static String Str_Replace(String handleStr, String pointStr, String repStr)
	{
		String str = new String();
		int pos1,pos2;
		try
		{
			if(handleStr.length()>0)
			{
				pos1 = handleStr.indexOf(pointStr);
				pos2 = 0;
				while(pos1 != -1)
				{
					str += handleStr.substring(pos2,pos1);
					str += repStr;
					pos2 = pos1+pointStr.length();
					pos1 = handleStr.indexOf(pointStr,pos2);
				}
				str += handleStr.substring(pos2);
			}
		}catch(Exception error)
		{
			//error.printStackTrace();
			System.out.println("LOG>> Have some error when replace file context.");
		}
		return str;
	}	

	public static String SymbolToHtml(String StrContent)
	{
		String StrSymbolHtml;

		StrSymbolHtml=Str_Replace(StrContent,"\n","<br>");

		StrSymbolHtml=Str_Replace(StrSymbolHtml," ","&nbsp;");
		
		return StrSymbolHtml;
	}
	public static String SymbolToUrl(String StrContent)
	{
		String StrSymbolUrl;

		StrSymbolUrl=Str_Replace(StrContent,"\n","<br>");
		StrSymbolUrl=Str_Replace(StrSymbolUrl,"'"," ");
		StrSymbolUrl=Str_Replace(StrSymbolUrl,"\""," ");
		return StrSymbolUrl;
	}

	public static String ToGb(String srcString)
    {
        String destString = "";
        try
        {
            if(srcString != null)
                destString = new String(srcString.getBytes("iso-8859-1"), "gb2312");
        }
        catch(Exception e)
        {
            System.out.print("Encoding Failer: ".concat(String.valueOf(String.valueOf(srcString))));
        }
        return destString;
    }

	public static String Filtrate(String strValue)
	{
		String strRetValue;
		strRetValue = Str_Replace(strValue,"'","''");
		strRetValue = Str_Replace(strRetValue,"\"","");
		return strRetValue;
	}
	public static String convdate(String strValue)
	{
		String strRetValue;
		strRetValue = Str_Replace(strValue,".","-");
		strRetValue = Str_Replace(strRetValue,"/","-");
		return strRetValue;
	}
	public static String convertDate(String strValue)
	{
		String strRetValue;
		String strYear;
		String str;
		String strMonth;
		String strDate;
		strYear = strValue.substring(0,4);
		str = strValue.substring(5,strValue.length());
		strMonth = str.substring(0,str.indexOf("-"));
		if(strMonth.length()==1)
		{
			strMonth = "0"+strMonth;
		}
		strDate = str.substring(str.indexOf("-")+1,str.length());
		if(strDate.length()==1)
		{
			strDate = "0"+strDate;
		}
		strRetValue = strYear+"-"+strMonth+"-"+strDate;
		return strRetValue;
	}
	public static String ValueToName(String strValue)
	{
		String strName;
		if (strValue==null || strValue.equals(""))
		{
			return "";
		}
		strName = ToGb(strValue.substring(0, strValue.indexOf("@")));
		return strName;
	}
	public static String ValueToCode(String strValue)
	{
		String strCode;
		if (strValue==null || strValue.equals(""))
		{
			return "";
		}
		strCode = ToGb(strValue.substring(strValue.indexOf("@")+1));
		return strCode;
	}

/** 
   * 将string类型转化为double类型 
   * @param s String 
   * @return double 
   */ 

	public static double sTod(String s)
	{ 
	   double d = -1d; 
	   if(s==null || s.length()==0)
	   { 
			return d; 
	   } 
	   try
	   { 
			 d = Double.parseDouble(s); 
	   }
	   catch(Exception e)
	   { 
			 System.out.println("String convert to double error"); 
		     return d; 
	   } 
		return d; 
	 } 

/** 
   * 将Integer包装器转化成int基本类型 
   * @param I Integer 
   * @return int 
   */ 
	  public static int integerToInt(Integer I)
	  { 
		if(I==null) 
		return 0; 
	    int i = I.intValue();	
		return i; 
	  } 

  /** 
   * 将int基本类型转化成Integer包装器对象 
   * @param i int 
   * @return Integer 
   */ 
	  public static Integer intToInteger(int i)
	  { 
		Integer I = new Integer(i); 
		return I; 
	  } 

  /** 
   * 将Charater 包装器对象转化成char基本类型 
   * @param C Character 
   * @return char 
   */ 
	  public static char charaterToChar(java.lang.Character C)
	  { 
		if(C==null) 
	    return '0'; 
		char c = C.charValue(); 
	    return c; 
	  } 

  /** 
   * 将char基本类型转化成Charater 包装器对象 
   * @param c char 
   * @return Character 
   */ 
	  public static Character charToCharater(char c)
	  { 
		Character C = new Character('c'); 
		return C; 
	  } 

  /** 
   * 将Long 包装器对象转化成long基本类型 
   * @param L Long 
   * @return long 
   */ 
	  public static long LongTolong(Long L)
	  { 
		if(L==null)
		{ 
	      return 0l; 
	    } 
		long l = L.longValue(); 
	    return l; 
	  } 

  /** 
   * 将long基本类型转化为Long包装器对象 
   * @param l long 
   * @return Long 
   */ 
	  public static Long longToLong(long l)
	  { 
		Long L = new Long(l); 
	    return L; 
	  } 
   
  /** 
   * 将Float包装器对象转化为float基本类型 
   * @param F Float 
   * @return float 
   */ 
	  public static float FloatTofloat(Float F)
	  { 
	    if(F==null)
		{ 
	      return -1f; 
		} 
	    float f = F.floatValue(); 
	    return f; 
	  } 
   
  /** 
   * 将float基本类型转化为Float包装器对象 
   * @param f float 
   * @return Float 
   */ 
	  public static Float floatToFloat(float f)
	  { 
		Float F = new Float(f); 
	    return F; 
	  } 

  /** 
   * 将Double包装器对象转化为double基本类型 
   * @param D Double 
   * @return double 
   */ 
	  public static double DoubleTodouble(Double D)
	  { 
	    if(D==null) 
		return 0D; 
	    double d = D.doubleValue(); 
		return d; 
	  } 

  /** 
   * 将double基本类型转化为Double包装器对象 
   * @param d double 
   * @return Double 
   */ 
	  public static Double doubleToDouble(double d)
	  { 
		Double D = new Double(d); 
	    return D; 
	  } 

  /** 
   * 将Boolean包装器对象转化为boolean基本类型 
   * @param B Boolean 
   * @return boolean 
   */ 
	  public static boolean BooleanToboolean(Boolean B)
	  { 
	    if(B==null) 
		return false; 
	    boolean b = B.booleanValue(); 
		return b; 
	  } 

  /** 
   * 将boolean基本类型转化为Boolean对象类型 
   * @param b boolean 
   * @return Boolean 
   */ 
	  public static Boolean booleanToBoolean(boolean b)
	  { 
	    Boolean B = new Boolean(b); 
		return B; 
	  } 

  /***************************各类型与string类型的相互转换***********************/ 
  /** 
   * 将String对象转化为int基本类型 
   * @param s String 
   * @return int 
   */ 
	  public static int sToi(String s)
	  { 
	    int i = -1; 
		if(s==null || s.trim().length()==0)
		{ 
	      return i; 
		} 
	    try
		{ 
	      i = Integer.parseInt(s); 
		}
		catch(Exception e)
		{ 
	      System.out.println("Stirng  convet to int error ! "); 
	      return i; 
		} 
	    return i; 
	  } 

  /** 
   * 将int类型转化为String 
   * @param i int 
   * @return String 
   */ 
	public static String iTos(int i)
	{ 
		String s = intToInteger(i).toString(); 
	    return s; 
	  } 
   
  /** 
   * 将string类型转化为long类型 
   * @param s String 
   * @return long 
   */ 
	  public static long sTol(String s )
	  { 
	    long l = -1L; 
		if(s==null || s.trim().length()==0)
		{ 
	      return l; 
		} 
	    try
		{ 
	      l = Long.parseLong(s); 
	    }
		catch(Exception e)
		{ 
	      System.out.println("String convert to long error!"); 
		  return l; 
	    }	
	   return l; 
	  } 

  /** 
   * 将long类型转化为String类型 
   * @param l long 
   * @return String 
   */ 
	  public static String lTos(long l)
	  { 
		String s = longToLong(l).toString(); 
	    return s; 
	  } 
  /** 
   * 将string类型转化为float类型 
   * @param s String 
   * @return float 
   */ 
	  public static float sTof(String s)
	  { 
		float f = -1f; 
	    if(s==null || s.length()==0)
		{ 
		     return f; 
		}     
	   try
		{ 
		     f = Float.parseFloat(s); 
	    }
		catch(Exception e)
		{ 
		     System.out.println("String convert to float error"); 
		     return f; 
		} 
	   return f; 
	 } 
  
 /** 
  * 将float类型转化为String类型 
  * @param f float 
  * @return String 
  */ 
	 public static String fTos(float f)
	 { 
		  String s = floatToFloat(f).toString(); 
		  return s; 
	 } 
  
 
 /** 
  * 将double类型转化为String类型 
  * @param d double 
  * @return String 
  */ 
	 public static String dTos(double d)
	 { 
		  String s = doubleToDouble(d).toString(); 
		  return s; 
	 } 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -