Here you can find the source of startsWithIgnoreWhitespaces(String prefix, String string)
Parameter | Description |
---|---|
prefix | a parameter |
string | a parameter |
public static boolean startsWithIgnoreWhitespaces(String prefix, String string)
//package com.java2s; /*/* w ww.j a va 2 s. c o m*/ * Copyright 2004,2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * Tests if this string starts with the specified prefix (Ignoring whitespaces) * * @param prefix * @param string * @return boolean */ public static boolean startsWithIgnoreWhitespaces(String prefix, String string) { int index1 = 0; int index2 = 0; int length1 = prefix.length(); int length2 = string.length(); char ch1 = ' '; char ch2 = ' '; while (index1 < length1 && index2 < length2) { while (index1 < length1 && Character.isWhitespace(ch1 = prefix.charAt(index1))) { index1++; } while (index2 < length2 && Character.isWhitespace(ch2 = string.charAt(index2))) { index2++; } if (index1 == length1 && index2 == length2) { return true; } if (ch1 != ch2) { return false; } index1++; index2++; } if (index1 < length1 && index2 >= length2) { return false; } return true; } }