![]() String replace(char oldChar, char newChar) This is like the previous method, except that it doesn’t have ignoreCase. Boolean regionMatches(int toffset, String other, int offset, int len) Scala> "Ayushi".regionMatches(true,0,"Ayush",0,3) Scala> "Ayushi".regionMatches(true,0,"Ayush",0,4) scala> "Ayushi".regionMatches(true,0,"Ayushi",0,4) ignoreCase, when set to true, will ignore the case differences. If two string regions are equal, this returns true otherwise, false. Boolean regionMatches(boolean ignoreCase, int toffset, String other, int offset, int len) If the string matches the regular expression we specify, this returns true otherwise, false. This Scala String Method method simply returns the length of a string. This Scala String Method is like the previous method, except that it begins searches at the index we specify, and searches right to left. int lastIndexOf(String str, int fromIndex) This Scala String Method returns the index of the last occurrence of the substring we specify, in the string. Here, it returns -1 because it couldn’t find ‘n’. This is like lastIndexOf, except that it begins searching backwards(right to left), starting at the index we specify. Unlike indexOf, this Scala String Method returns the index of the last occurrence of the character we specify. Intern returns the canonical representation for the string object. Like the other version of indexOf for a single character, this begins searching at the index we specify. This Scala String Method returns the index of the first occurrence of the substring we specify, in the string. This is like indexOf, except that it begins searching at the index we specify. ![]() This Scala Sring returns the index of the first occurrence of the character ch in the string. This int hashCode method returns a hash code for the string. dstBegin denotes the index to begin at in the destination character array. scrBegin denotes the index to begin at in the source string, and srcEnd denotes the index to end at in the source string. This Scala String Method copies characters from the string into the destination character array. void getChars(int srcBegin, int srcEnd, char dst, int dstBegin) Java.io.UnsupportedEncodingException: UnionĪt (Unknown Source)Īt (Unknown Source) However, providing an invalid charset name will result in an error: scala> "Ayushi".getBytes("Union") With a named charset as a parameter, getBytes will use that charset to encode the string. It uses the platform’s default charset for this. GetBytes Scala String Method encodes a string into a sequence of bytes and stores it into a new byte array. scala> "Ayushi".equalsIgnoreCase("aYushi") This is like equals(), except that it ignores case differences. Boolean equalsIgnoreCase(String anotherString) This Scala String Method returns true if the string and the object are equal otherwise, false. This Scala String Method returns true if the string ends with the suffix specified otherwise, false. If equal, it returns true otherwise, false. Boolean contentEquals(StringBuffer sb)ĬontentEquals compares a string to a StringBuffer’s contents. We saw this when we talked about strings briefly. This will concatenate the string in the parameter to the end of the string on which we call it. Scala> "Ayushi".compareToIgnoreCase("aYushi") Scala> "Ayushi".compareToIgnoreCase("ayushi ") ![]() scala> "Ayushi".compareToIgnoreCase("ayushi") Int compareToIgnoreCase Scala String Method compares two strings lexicographically, while ignoring the case differences. scala> "Ayushi".compareTo("Ayushi ")Ĭomparing to a different type raises a type-mismatch error. Otherwise, it returns the difference between the two(the number of characters less in the shorter string, or the maximum ASCII difference between the two). This is like the previous one, except that it compares two strings lexicographically. This Scala String Method compares a string to another object. Isn’t it so much like Java? scala> "Ayushi".charAt(1) This method returns the character at the index we pass to it. List of String Method in Scala with Example 1.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |