Common String functions Left, Right, Leftback, Rightback

package com.xpagedeveloper;

public class CString{
	public static String RightBack(String Source,String Find){
		int pos=Source.lastIndexOf(Find);
		if(pos>0){
			if(pos+Find.length()==Source.length()){
				return "";
			}else{
				return Source.substring(pos+Find.length());
			}
		}else{
			return Source;
		}
	}
	public static String LeftBack(String Source,String Find){
		int pos=Source.lastIndexOf(Find);
		if(pos>0){
				return Source.substring(0,pos);
		}else{
			return Source;
		}
	}
	public static String Right(String Source,String Find){
		int pos=Source.indexOf(Find);
		if(pos>0){
			return Source.substring(pos+Find.length());
		}else{
			return Source;
		}
	}
	public static String Left(String Source,String Find){
		int pos=Source.indexOf(Find);
		if(pos>0){
			return Source.substring(0,pos);
		}else{
			return Source;
		}
	}
	public static String ReplaceSubstring(String Source,String Find,String ReplaceWith){
	    if(Find.equals(".")){
	        Find="\\"+Find;
	    }
	    return Source.replaceAll(Find,ReplaceWith);
	}
}





Some common string function in Java that I use in SSJS and Lotusscript all the time.

feel free to improve them.

http://www.xpagedeveloper.com

Java
Fredrik Norling
January 5, 2016 5:18 PM
Rating
117

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.



No comments yetLogin first to comment...