_methods

trait _Methods extends _evaluate with _modify with _copy with _transform

String Extension Methods

Extension methods universaly avaialble for type java.lang.String

Source
__.scala
trait _copy
trait _modify
trait _evaluate
class java.lang.Object
trait scala.Matchable
class Any

Def

@targetName("joinTag")
inline def ++(v: A)(using d: Any.Def.Tag[A]): String

Join tag

Join tag

Joins value tag to base string.

Use it instead of '+'. Single plus joins '.toString' instead of '.tag', which often does not make sense especially for 'opaque values'

Note. This method should logically be called '+'. However, it is already defined in 'final class String' and cannot be overridden.

  val p = 12.Percent

  val s = "Value: " ++ p

  // same result as

  val s = "Value: " + p.tag
Inherited from
_modify
Source
_modify.scala
@targetName("joinOpt")
inline def +?(v: Opt[A])(using d: Any.Def.Tag[A]): String

Optional join

Optional join

Joins option value to base string.

Returns String "as is" for empty option.

Inherited from
_modify
Source
_modify.scala
inline def charAt(i: Int): Char

Char at position

Char at position

Returns Char at the specified position

Inherited from
_evaluate
Source
_evaluate.scala
inline def charAtOpt(i: Int): Char.Opt

Char at position

Char at position

Optionally Returns Char at the specified position

VOID is returned if specified position is out of String range

if(<name>.charAtOpt(2).take(_.isUpper)) ()
// is equivalent
if(<name>.length >=2 && <name>.charAt(2).isUpper) ()
Inherited from
_evaluate
Source
_evaluate.scala
inline def charIndexOpt(f: Char => Boolean, from: Int.Opt): Int.Opt

Char index

Char index

Optionally returns index of the first Char passing the let function

   "abcd_abcd_".charIndexOpt(_ >= 'd', 4).tp // Prints: Opt(8)
   "abcd_abcd_".charIndexOpt('x' <> 'z') tp  // Prints: Opt(VOID)
Value Params
from

position to start looking from

Inherited from
_evaluate
Source
_evaluate.scala

Stream of Chars

Stream of Chars

Returns String as a Stream of [Char]]

"abcd".charStream.tp // Prints Stream(a, x, c, d)
Inherited from
_transform
Source
_transform.scala
inline def compareTo(v: String): Int
Inherited from
_evaluate
Source
_evaluate.scala
inline def contains(v: String): Boolean

Contains check

Contains check

Returns true is this String contains that String

"abc".contains("cd").tp // Prints: false
Inherited from
_evaluate
Source
_evaluate.scala
inline def dropFirst(cnt: Int): String

Copy without start

Copy without start

Copies without given number of first characters

The method call is inlined as Java .substring(cnt)

Inherited from
_copy
Source
_copy.scala
inline def dropLast(cnt: Int): String

Copy without end

Copy without end

Copies without given number of last characters

The method call is inlined as Java x.substring(0, x.length - cnt)

Inherited from
_copy
Source
_copy.scala
inline def dropRange(i: Int.Range): String

Copy without range

Copy without range

Copies without range of characters specified

Inherited from
_copy
Source
_copy.scala
inline def dropRange(start: Int, size: Int): String

Copy without range

Copy without range

Copies without range of characters specified

Inherited from
_copy
Source
_copy.scala
inline def endsWith(v: String): Boolean

Check if ends with

Check if ends with

Returns true this String ends with that String

"abc".endsWith("bc").tp // Prints: true
Inherited from
_evaluate
Source
_evaluate.scala
inline def equalsIgnoreCase(v: String): Boolean

Check if equals ignore case

Check if equals ignore case

Returns true this and that String are equal, if upper and lower case Chars are considered equal

"aBc".equalsIgnoreCase("ABC").tp // Prints: true
Inherited from
_evaluate
Source
_evaluate.scala
inline def indent(tag: String): String

Indents text with the lines

Indents text with the lines

Indents text with the tag.

Prefixes first line with the tag, other lines with tag equal space

```
   "abc\

de
xyz".indent("Idxs: ").tp // Output Idxs: abc de xyz ```

Inherited from
_transform
Source
_transform.scala
inline def indexOfOpt(v: String, from: Int.Opt): Int.Opt

Value position

Value position

Optionally returns position of the specified x

"abcd_abcd_".indexOfOpt("d_a").tp // Prints: Opt(3)
Value Params
from

position to start looking from

Inherited from
_evaluate
Source
_evaluate.scala
inline def indexOfStream(v: String, from: Int.Opt): Int.Stream

Source of indexes

Source of indexes

Source of indexes for each occurrence of x

"abcd_abcd_abcd_abcd_abcd".indexOfStream("bc").tp // Prints Stream(1, 6, 11, 16, 21)
Value Params
from

position to start looking from

Inherited from
_evaluate
Source
_evaluate.scala
inline def insertAt(i: Int, v: String): String

Insert at position

Insert at position

Creates new String with x inserted at the specified position

"0123456789".insertAt(5,"abc").tp // Prints: 01234abc56789
Inherited from
_modify
Source
_modify.scala
inline def label: String

Capitalize

Capitalize

Capitalizes first character of every word (separated by white spaces)

"all string ops".label.tp // Prints: All String Ops
Inherited from
_modify
Source
_modify.scala
inline def lastCharIndexOpt(f: Char => Boolean, from: Int.Opt): Int.Opt

Char index

Char index

Optionally returns index of the last Char passing the let function

   "abcd_abcd_".lastCharIndexOpt(_ >= 'd', 4).tp // Prints: Opt(3)
   "abcd_abcd_".lastCharIndexOpt('x' <> 'z') tp  // Prints: Opt(VOID)
Value Params
from

last position to start looking from end to start

Inherited from
_evaluate
Source
_evaluate.scala
inline def lastIndexOfOpt(v: String, from: Int.Opt): Int.Opt

Value position

Value position

Optionally returns last position of the specified x

"abcd_abcd_abcd_".lastIndexOfOpt("d_a").tp // Prints: Opt(8)
Value Params
from

last position to start looking from end to start

Inherited from
_evaluate
Source
_evaluate.scala
inline def length: Int
Inherited from
_evaluate
Source
_evaluate.scala
inline def lineStream: Stream[String]

Stream of lines

Stream of lines

Creates a [[Stream]] of Strings representing lines (delimited by '

') of this text

```
"abc\

def
xyz".lineStream.tp // Prints Stream(abc, def, xyz) ```

Inherited from
_transform
Source
_transform.scala
inline def lower: String

toLowerCase

toLowerCase

Creates new String with all upper case Chars changed to lower case

"ABc".lower.tp // Prints: abc
Inherited from
_modify
Source
_modify.scala
inline def padEndTo(size: Int, pad: String): String

Pad end

Pad end

  Pads end of string to `targetLength`
Value Params
pad

string to pad with. "ABC".padEndTo(10,"_").tp // Prints: ABC_______

Inherited from
_modify
Source
_modify.scala
inline def padStartTo(size: Int, pad: String): String

Pad start

Pad start

  Pads start of string to `targetLength`
Value Params
pad

string to pad with. "ABC".padStartTo(10,"_").tp // Prints: _______ABC

Inherited from
_modify
Source
_modify.scala
inline def remove(v: String): String

Remove all

Remove all

Creates new String with all occurrences of x removed

"123123123123".remove("2").tp // Prints: 13131313
Inherited from
_modify
Source
_modify.scala
inline def replace(v: String, target: String): String

Replace all

Replace all

Creates new String with all occurrences of x replaced with target

"123123123123".replace("2","_").tp // Prints: 1_31_31_31_3
Inherited from
_modify
Source
_modify.scala
inline def replace(r: Int.Range, v: String): String

Replace range with x

Replace range with x

Creates new String with all occurrences of x replaced with target

"0123456789".replace(3 <> 7 ,"_").tp // Prints: 012_89
Inherited from
_modify
Source
_modify.scala
inline def replaceFirst(v: String, v2: String, cnt: Int): String
Inherited from
_modify
Source
_modify.scala
inline def replaceLast(v: String, v2: String, cnt: Int): String
Inherited from
_modify
Source
_modify.scala
inline def splitStream(sep: Char, more: Char*): Stream[String]
Inherited from
_transform
Source
_transform.scala
inline def startsWith(v: String): Boolean

Check if begins with

Check if begins with

Returns true this String starts with that String

"abc".startsWith("ab").tp // Prints: true
Inherited from
_evaluate
Source
_evaluate.scala
inline def takeAfter(v: String, dflt: Opt[String], fromPosition: Int.Opt): String

Copy end

Copy end

Copies String from the position where the specified v found plus the length of the v

If no v found, dflt v is returned, or original if dflt is void

   "abcdefg".copyAfter("cd").tp // Prints: efg
Value Params
string

position to start looking from

Inherited from
_copy
Source
_copy.scala
inline def takeAfterLast(v: String, dflt: Opt[String], fromPosition: Int.Opt): String

Copy end

Copy end

Copies String from the last position the specified v found plus the length of the v

If no v found, dflt v is returned, or original if dflt is void.

   "abcd_abcd_abcd".takeFromLast("ab").tp // Prints: cd
Value Params
from

string last position to start looking from end to start

Inherited from
_copy
Source
_copy.scala
inline def takeBefore(v: String, dflt: Opt[String], fromPosition: Int.Opt): String

Copy start

Copy start

Copies String from the beginning until specified v found

If no v found, dflt v is returned, or original if dflt is void

   "abcdefg".takeBefore("ef").tp // Prints: abcd
Value Params
string

position to start looking from

Inherited from
_copy
Source
_copy.scala
inline def takeBeforeLast(v: String, dflt: Opt[String], fromPosition: Int.Opt): String

Copy start

Copy start

Copies String from the beginning until the last occurrence of specified v found

If no v found, dflt v is returned, or original if dflt is void

   "abcd_abcd_abcd".copyBeforeLast("ab").tp // Prints: abcd_abcd_
Value Params
from

string last position to start looking from end to start

Inherited from
_copy
Source
_copy.scala
inline def takeFirst(cnt: Int): String

Copy start

Copy start

Copies first given number of characters

The method call is inlined as Java x.substring(0,cnt)

Inherited from
_copy
Source
_copy.scala
inline def takeFrom(v: String, dflt: Opt[String], fromPosition: Int.Opt): String

Copy end

Copy end

Copies String from the position where the specified v found

If no v found, dflt v is returned, or original if dflt is void

   "abcdefg".takeFrom("cd").tp // Prints: cdefg
Value Params
string

position to start looking from

Inherited from
_copy
Source
_copy.scala
inline def takeFromLast(v: String, dflt: Opt[String], fromPosition: Int.Opt): String

Copy end

Copy end

Copies String from the last position the specified v found

If no v found, dflt v is returned, or original if dflt is void.

   "abcd_abcd_abcd".takeFromLast("ab").tp // Prints: abcd
Value Params
from

string last position to start looking from end to start

Inherited from
_copy
Source
_copy.scala
inline def takeLast(cnt: Int): String

Copy end

Copy end

Copies last given number of characters

The method call is inlined as Java x.substring(x.length - cnt, x.length)

Inherited from
_copy
Source
_copy.scala
inline def takeRange(r: Int.Range): String

Copy range

Copy range

Copies only range of characters specified

Inherited from
_copy
Source
_copy.scala
inline def takeRange(start: Int, size: Int): String

Copy range

Copy range

Copies only range of characters specified

Inherited from
_copy
Source
_copy.scala

Boolean option conversion

Boolean option conversion

Converts String to Boolean option

 "true".toBooleanOpt.tp

 "abc".toBooleanOpt.tp

 // Output
 Boolean.Opt(true)
 Boolean.Opt(VOID)
Inherited from
_transform
Source
_transform.scala
inline def toBooleanResult: Result[Boolean]

Boolean result conversion

Boolean result conversion

Converts String to Boolean result

 "true".toBooleanResult.tp

 "abc".toBooleanResult.tp

 // Output
 Result(true)
 Result(Problem(For input string: "abc"))
Inherited from
_transform
Source
_transform.scala

Double option conversion

Double option conversion

Converts String to Double option

 "123.45".toDoubleOpt.tp

 "abc".toDoubleOpt.tp

 // Output
 Double.Opt(123.45)
 Double.Opt(VOID)
Inherited from
_transform
Source
_transform.scala
inline def toDoubleResult: Result[Double]

Double result conversion

Double result conversion

Converts String to Double result

 "123.45".toDoubleResult.tp

 "abc".toDoubleResult.tp

 // Output
 Result(123.45)
 Result(Problem(For input string: "abc"))
Inherited from
_transform
Source
_transform.scala
inline def toIntOpt: Int.Opt

Int opt conversion

Int opt conversion

Converts String to Int option

 "123".toIntOpt.tp

 "abc".toIntOpt.tp

 // Output
 Int.Opt(123)
 Int.Opt(VOID)
Inherited from
_transform
Source
_transform.scala
inline def toIntResult: Result[Int]

Int result conversion

Int result conversion

Converts String to Int result

 "123".toIntResult.tp

 "abc".toIntResult.tp

 // Output
 Result(123)
 Result(Problem(For input string: "abc"))
Inherited from
_transform
Source
_transform.scala
inline def tokenizedStream(separators: Stream[String]): Stream[(String, Int.Range, String)]

Stream of tokens

Stream of tokens

Multi token tokenizetion

Returns a Tuple including:

  • Separator preceding the token, empty for the first token
  • !.Range of the token in the text
  • String token
  val str: String = (1 <> 40).stream.makeString("")
  "Text to Tokenize:".tp.tp
  str.tp.tp
  ("Token", "Range", "String").tp
  str.tokenizedStream(Stream("000","111","222","333","444")).print

  // Output

  Text to Tokenize:

 12345678910111213141516171819202122232425262728293031323334353637383940

  (Token,Range,String)
  --- --------- -------------------
  ?   ?         ?
  --- --------- -------------------
       0 <>> 11 12345678910
  111 14 <>> 33 2131415161718192021
  222 36 <>> 55 3242526272829303132
  333 58 <>> 71 4353637383940
  --- --------- -------------------
Value Params
separators

a Stream of text separators to consider

Inherited from
_transform
Source
_transform.scala
inline def toLongOpt: Long.Opt

Long option conversion

Long option conversion

Converts String to Long option

  "123".toLongOpt.tp

  "abc".toLongOpt.tp

  // Output
  Long.Opt(123)
  Long.Opt(VOID)
Inherited from
_transform
Source
_transform.scala
inline def toLongResult: Result[Long]

Long result conversion

Long result conversion

Converts String to Long result

  "123".toLongResult.tp

  "abc".toLongResult.tp

  // Output
  Result(123)
  Result(Problem(For input string: "abc"))
Inherited from
_transform
Source
_transform.scala
inline def trim: String

Trim both ends

Trim both ends

Trims both ends of String from space Chars

Inherited from
_modify
Source
_modify.scala
inline def trimBoth(f: Char => Boolean): String

Trim both ends

Trim both ends

Trims both ends of String from Chars defined by let function

   "yyxxxxABCxxyyxx".trimBoth(_ in 'x' <> 'z') tp           // Prints: ABC

   "yyxxxxABCxxyyxx".trimBoth(c => c == 'x' || c == 'y').tp // Prints: ABC
Inherited from
_modify
Source
_modify.scala
inline def trimEnd(f: Char => Boolean): String

Trim end

Trim end

Trims end of String from Chars defined by let function

   "ABCxxyyxx".trimEnd(_ in 'x' <> 'z') tp           // Prints: ABC

   "ABCxxyyxx".trimEnd(c => c == 'x' || c == 'y').tp // Prints: ABC
Inherited from
_modify
Source
_modify.scala
inline def trimEnd: String

Trim end

Trim end

Trims end of String from space Chars

Inherited from
_modify
Source
_modify.scala
inline def trimStart(f: Char => Boolean): String

Trim start

Trim start

Trims start of String from Chars defined by let function

   "yyxxxxABC".trimStart(_ in 'x' <> 'z') tp           // Prints: ABC

   "yyxxxxABC".trimStart(c => c == 'x' || c == 'y').tp // Prints: ABC
Inherited from
_modify
Source
_modify.scala
inline def trimStart: String

Trim start

Trim start

Trims start of String from space Chars

Inherited from
_modify
Source
_modify.scala
inline def upper: String

toUpperCase

toUpperCase

Creates new String with all lower case Chars changed to upper case

"aBc".upper.tp // Prints: ABC
Inherited from
_modify
Source
_modify.scala

Make

To Problem

To Problem

Creates Result.Problem, where the base String becomes problem message

Inherited from
_transform
Source
_transform.scala