BBjString

Description

In BBj 7.0 and higher, the BBjString object defines an object-oriented interface to traditional BBx strings. It implements most of the methods defined by java.lang.String. This API is primarily designed to facilitate interaction with Java libraries.

Creation

BBjAPI > BBjString

All string values created in BBj are BBjStrings. To access BBjString methods, copy a BBj string value to an object variable:

string! = "Hello world"
print string!.length()

Methods of BBjString

Return Value

Method

char

charAt(int index)

int

codePointAt(int index)

int

codePointBefore(int index)

int

codePointCount(int beginIndex, int endIndex)

int

compareTo(string anotherString)

int

compareToIgnoreCase(string str)

string

concat(string str)

boolean

contains(CharSequence c)

boolean

contentEquals(CharSequence cs)

contentEquals(StringBuffer sb)

boolean

endsWith(string suffix)

boolean

equals(Object anObject)

boolean

equalsIgnoreCase(string anotherString)

byte[]

getBytes()

getBytes(string charsetName)

void

getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin)

void

getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)

int

hashCode()

string

indent(int n)

int

indexOf(int ch)

indexOf(int ch, int fromIndex)

indexOf(string str)

indexOf(string str, int fromIndex)

string

intern()

boolean isBlank()

boolean

isEmpty()

int

lastIndexOf(int ch)

lastIndexOf(int ch, int fromIndex)

lastIndexOf(string str)

lastIndexOf(string str, int fromIndex)

int

length()

boolean

matches(string regex)

int

offsetByCodePoints(int index, int codePointOffset)

boolean

regionMatches(boolean ignoreCase, int toffset, string other, int ooffset, int len)

regionMatches(int toffset, string other, int ooffset, int len)

string

repeat(int count)

string

replace(CharSequence target, CharSequence replacement)

replace(char oldChar, char newChar)

string

replaceAll(string regex, string replacement)

string

replaceFirst(string regex, string replacement)

String[]

split(string regex)

split(string regex, int limit)

boolean

startsWith(string prefix)

startsWith(string prefix, int toffset)

string strip()
string stripIndent()
string stripLeading()
string stripTrailing()

CharSequence

subSequence(int beginIndex, int endIndex)

string

substring(int beginIndex)

substring(int beginIndex, int endIndex)

char[]

toCharArray()

string

toLowerCase()

toLowerCase(Locale locale)

string

toUpperCase()

toUpperCase(Locale locale)

string translateEscapes()

string

trim()

 

Remarks

None.

Constants

None.

Example

rem ' BBjString

print "BBjString sample code"

x! = "The quick brown fox jumps over the lazy dog"

print "x! = """,x!,""""
print "x!.charAt(0)=",x!.charAt(0); rem 'T'
print "x!.codePointAt(0)=",x!.codePointAt(0); rem 84
print "x!.codePointBefore(1)=",x!.codePointBefore(1); rem 84

l = x!.length()
print "x!.codePointCount(0,x!.length())=",x!.codePointCount(0,l); rem 43
print "x!.compareTo(""The"")=",x!.compareTo("The"); rem 40
print "x!.compareToIgnoreCase(""THE"")=",x!.compareToIgnoreCase("THE"); rem 40
print "x!.concat(""."")=",x!.concat(".")
print "x!.contains(""quick"")=",x!.contains("quick"); rem true
print "x!.contains(""slow"")=",x!.contains("slow"); rem false

sb! = new StringBuffer(x!)
print "StringBuffer sb! = """,sb!,""""
print "x!.contentEquals(sb!)=",x!.contentEquals(sb!); rem true
print "x!.endsWith(""dog"")=",x!.endsWith("dog"); rem true
print "x!.endsWith(""cat"")=",x!.endsWith("cat"); rem false
print "x!.equals(sb!)=",x!.equals(sb!); rem false
print "x!.equals(sb!.toString())=",x!.equals(sb!.toString()); rem true

y! = x!.toUpperCase()
print "y! = """,y!,""""
print "x!.equals(y!)=",x!.equals(y!); rem false
print "x!.equalsIgnoreCase(y!)=",x!.equalsIgnoreCase(y!); rem true
print "x!.getBytes()=",x!.getBytes()," {",x!.getBytes().getClass(),"}"
c! = java.lang.reflect.Array.newInstance(Character.TYPE,x!.length())
x!.getChars(0,x!.length(),c!,0)
print "x!.getChars()=",java.util.Arrays.toString(c!)
print "x!.hashCode()=",x!.hashCode()
print "x!.indexOf(""q"")=",x!.indexOf("q"); rem 4
print "x!.intern()=",x!.intern()
print "x!.isEmpty()=",x!.isEmpty()
print "x!.lastIndexOf(""the"")=",x!.lastIndexOf("the"); rem 31
print "x!.length()=",x!.length(); rem 43
print "x!.matches(""^The.*"")=",x!.matches("^The.*"); rem true
print "x!.offsetByCodePoints(0,1)=",x!.offsetByCodePoints(0,1); rem 1
print "x!.regionMatches(1,x!,32,2)=",x!.regionMatches(1,x!,32,2); rem true
print "x!.replace(""dog"",""cat"")=",x!.replace("dog","cat")
print "x!.replaceAll("" "",""_"")=",x!.replaceAll(" ","_")
print "x!.replaceFirst("" "",""_"")=",x!.replaceFirst(" ","_")
print "x!.split("" "")=",java.util.Arrays.toString(x!.split(" "))
print "x!.startsWith(""The"")=",x!.startsWith("The"); rem true
print "x!.substring(4,9)=""",x!.substring(4,9),""""; rem quick
print "x!.subSequence(4,9)=""",x!.subSequence(4,9),""""; rem quick
print "x!.toCharArray()=",java.util.Arrays.toString(x!.toCharArray())
print "x!.toLowerCase()=",x!.toLowerCase()
print "x!.toUpperCase()=",x!.toUpperCase()
print "x!.trim()=""",x!.trim(),""""

print ""
print "BBjString methods added in BBj 23.04:"
x! = "   The quick brown fox jumps over the lazy dog.  "
print "x! = """,x!,""""
print "x!.indent(5)=",x!.indent(5)
print "x!.isBlank()=",x!.isBlank()
print "x!.repeat(2)=",x!.repeat(2)
print "x!.strip()=""",x!.strip(),""""
print "x!.stripIndent()=""",x!.stripIndent(),""""
print "x!.stripLeading()=""",x!.stripLeading(),""""
print "x!.stripTrailing()=""",x!.stripTrailing(),""""

x! = "The quick brown fox\njumps over the lazy dog"
print "x! = ",x!
print "x!.translateEscapes()=",x!.translateEscapes()

See Also

BBjAPI

BBj Object Variables

java.lang.String

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.