Directly on the code:
/** * Project Name: * File Description: EXCEL Formula Type: String Formula * Main Features: * Version number: 1.0 * Producer: Liu Morning * created: 2013-12-3 **/package excel;/** * @author LCX * */public class Stringfunctions {public static string right (string Str,int len) {if (Len>str.length ()) throw new illegal ArgumentException ("Intercept length cannot be greater than the length of the array"), Return Str.substring (Str.length ()-len, Str.length ());} public static string left (string Str,int len) {if (Len>str.length ()) throw new IllegalArgumentException ("Intercept length cannot be greater than the length of the array "); return str.substring (0, Len);} public static string mid (String Str,int Start,int len) {if (Start+len-1>str.length ()) throw new IllegalArgumentException ("intercept more Limited"); return str.substring (Start-1, start+len-1);} public static int len (String str) {if (str==null) return 0;return str.length ();} public static string concatenate (String...strs) {stringbuffer buffer=new stringbuffer (); for (String Str:strs) Buffer.append (str); return buffer.tostring ();} public static Boolean exact (String str1,string str2) {return str1.equals (STR2);} public static string upper (String str1{if (str1==null) return "", return Str1.touppercase ();} public static int Find (String find_text,string within_text,int start_num) {if (start_num<=0| | Start_num>within_text.length ()) throw new IllegalArgumentException ("start_num parameter input problem"); if (Find_text.length () >within_text.length ()) return-1; String tag=within_text.substring (start_num-1), int index=tag.indexof (find_text), if (index<0) Return-1;return Index+start_num;} public static void Main (string[] args) {/******************* test string *****************************/system.out.println ( Mid ("I Want to Program", 2,2)); System.out.println (Left ("I Want to Program", 2)); System.out.println (Right ("I Want to Program", 3)); SYSTEM.OUT.PRINTLN (Concatenate ("A", "B", "C", "D")); System.out.println (Exact (new string ("AAA"), New String ("AAA")); SYSTEM.OUT.PRINTLN (Upper ("AAAA")); System.out.println (Find ("B", "ABCABC", 3));}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java implementation Excel Formula special topic (iv)--string function