Operating environment: jdk1.7, scala-2.10.4
Study
/**
* Document: This type of function----> Test string
* USER:YANGJF
* DATE:2016/8/14 8:07
* Image Array, Strings are not direct sequences, but they can be converted to sequences,
And they also support all sequence operations on strings here are some examples where you can understand how to operate on a string */Objectteststring {defMain (args:array[string]) {ValCc=teststring () println ("Uppercase conversion:"+cc.changeupper ("ABCDE")) println ("Lowercase conversion:"+cc.changelower ("Qwer")) println ("Sequential reversal:"+CC.REVERSESTR ("123456789")) println ("Deletes the element at the specified location:"+cc.dropelement ("0987654321")) println ("Gets the element at the specified location:"+cc.substring ("1234567")) println ("Get sequence:"+CC.SEQUNCESTR ("QAZXSW")) println ("add element:"+cc.addelement ("1234qwer")) println ("gets the subscript where the element is located:"+cc.getindex ("a")) println ("Gets the element value for the specified subscript:"+cc.getcharat (2)) println ("contains the specified character:"+cc.containsis ("G")//The return value is True or false}Case ClassTestString () {Lazy ValStr="ABCDEFGHIJKLMNOPQRSTUVWXYZ" Uppercase ConversiondefChangeupper (str:string) ={Str.map (_.toupper)}//Lowercase conversiondefChangelower (str:string) ={Str.map (_.tolower)}//InvertdefReversestr (str:string) ={Str.reverse}//Culling elementdefDropelement (str:string) ={Str.drop (2)//Remove the element labeled 2}//intercept the element at the specified positiondefSubString (str:string) ={str.slice (1,3)//before package}//Get sequencedefSequncestr (str:string) ={ValS:seq[char] = str s}//Get sequencedefAddElement (str:string) ={Str.concat ("Hello")}//Get subscriptdefGetIndex (str2:string) ={str.indexof (STR2)}//Gets the element with the specified subscriptdefGetcharat (I:int) ={Str.charat (i)}//contains this elementdefContainsis (foo:string) ={str.contains (foo)}}}
Run result value:
Uppercase conversion: ABCDE
lowercase conversion: qwer
order reversal: 987654321
Delete the element at the specified position: 87654321
Gets the element at the specified position: the
fetch sequence: QAZXSW
add element: 1234qwerhello
Gets the subscript where the element is located: 0
Gets the element value that specifies the subscript: C
contains the specified character: true