implicit class GrizzledString extends AnyRef
An analog to Scala's RichString
class, providing some methods
that neither RichString
nor String
provide. By
importing the implicit conversion functions, you can use the methods in
this class transparently from a String
or RichString
object.
Examples
These examples assume you've included this import:
import grizzled.string.Implicits.String._
These are just a few of the enrichments available. See below for the entire set.
val s = "a b c" println(s.tokenize) // prints: List(a, b, c)
" abc def ".rtrim // yields " abc def"
"© 2016 The Example Company" // yields "© 2016 The Example Company™
- Alphabetic
- By Inheritance
- GrizzledString
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new GrizzledString(string: String)
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
chomp: String
Like perl's
chomp()
: Remove any newline at the end of the line.Like perl's
chomp()
: Remove any newline at the end of the line.- returns
the possibly modified line
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
escapeNonPrintables: String
Escape any non-printable characters by converting them to metacharacter sequences.
Escape any non-printable characters by converting them to metacharacter sequences.
- returns
the possibly translated string
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
ltrim: String
Trim white space from the front (left) of a string.
Trim white space from the front (left) of a string.
- returns
possibly modified string
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
replaceFirstChar(c: Char, replacement: String): String
Replace the first instance of the specified character with string, returning the new string.
Replace the first instance of the specified character with string, returning the new string. This method differs from the JDK's
replaceFirst()
method in that it takes a target character, not a regular expression. It's ideal when you don't want to worry about escaping a regular expression metacharacter.- c
the character to find
- replacement
the replacement string
- returns
the (possibly changed) new string
-
def
replaceFirstChar(c: Char, replacement: Char): String
Replace the first instance of the specified character with another character, returning the new string.
Replace the first instance of the specified character with another character, returning the new string. This method differs from the JDK's
replaceFirst()
method in that it takes a target character, not a regular expression. It's ideal when you don't want to worry about escaping a regular expression metacharacter.- c
the character to find
- replacement
the replacement character
- returns
the (possibly changed) new string
-
def
rtrim: String
Trim white space from the back (right) of a string.
Trim white space from the back (right) of a string.
- returns
possibly modified string
- val string: String
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
toTokens: List[StringToken]
Tokenize the string on white space, returning
Token
objects.Tokenize the string on white space, returning
Token
objects. This method is useful when you need to keep track of the locations of the tokens within the original string.- returns
A list of tokens, or
Nil
if there aren't any.
-
def
toTokens(delims: String): List[StringToken]
Tokenize the string on a set of delimiter characters, returning
Token
objects.Tokenize the string on a set of delimiter characters, returning
Token
objects. This method is useful when you need to keep track of the locations of the tokens within the original string.- delims
the delimiter characters
- returns
A list of tokens, or
Nil
if there aren't any.
-
def
tokenize(delims: String): List[String]
Tokenize the string on a set of delimiter characters.
Tokenize the string on a set of delimiter characters.
- delims
the delimiter characters
- returns
A list of tokens, or
Nil
if there aren't any.
-
def
tokenize: List[String]
Tokenize the string on white space.
Tokenize the string on white space. An empty string and a string with only white space are treated the same. Note that doing a
split("""\s+""").toList
on an empty string ("") yields a list of one item, an empty string. Doing the same operation on a blank string (" ", for example) yields an empty list. This method differs fromsplit("""\s+""").toList
, in that both cases are treated the same, returning aNil
.- returns
A list of tokens, or
Nil
if there aren't any.
-
def
translateMetachars: String
Translate any metacharacters (e.g,.
Translate any metacharacters (e.g,. \t, \n, \\u2122) into their real characters, and return the translated string. Metacharacter sequences that cannot be parsed (because they're unrecognized, because the Unicode number isn't four digits, etc.) are passed along unchanged.
- returns
the possibly translated string
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )