Java tutorial
//package com.java2s; public class Main { public static String getSringBeforeChar(String sourceStr, char ch) { StringBuffer sb = new StringBuffer(sourceStr); StringBuffer newSb = new StringBuffer(); for (int i = 0; i < sb.length(); i++) { if (sb.charAt(i) == ch) { break; } newSb.append(sb.charAt(i)); } return newSb.toString(); } }