Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyString(characters : Array[Char])
- {
- require(characters != null)
- private val buffer = new Array[Char](characters.length)
- System.arraycopy(characters, 0, buffer, 0, characters.length)
- def this(input : String) = this(input.toCharArray)
- def length = buffer.length
- override def toString = new String(buffer)
- def substr(pos : Int, len : Int) : MyString =
- {
- require(pos >= 0 && pos < this.length && len > 0 && (pos + len) <= this.length)
- new MyString(buffer.slice(pos, pos + len))
- }
- def substr(pos : Int) : MyString = substr(pos, this.length - pos)
- }
- var a = new MyString("johnny")
- println(a.substr(0))
Add Comment
Please, Sign In to add comment