0

just wondering how to append a slice to the end of the slice IE val alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" alpha.slice(13,26) "NOPQRSTUVWXYZ" then add to "ABCDEFGHIJKLM" to produce NOPQRSTUVWXYZABCDEFGHIJKLM.

My teacher has asked us to produce Map[Int, string]. been stuck banging my head against the wall on this for a fair while Thanks

Madi
  • 25
  • 5

1 Answers1

2

This is a simple method:

(alpha + alpha).slice(13, 13+26)

See the article referenced in the comments for more efficient ways of doing this.


As a method this is

def rotateString(s: String, offset: Int): String =
  (s + s).slice(offset, offset + s.length)
Tim
  • 26,753
  • 2
  • 16
  • 29
  • In a testing situation how do you make that variable? `Table(1).mkString should be ("BCDEFGHIJKLMNOPQRSTUVWXYZA")` or `Table(13).mkString should be ("NOPQRSTUVWXYZABCDEFGHIJKLM")` – Madi Mar 26 '20 at 11:21