tslices.nim 807 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. discard """
  2. output: '''
  3. 456456
  4. 456456
  5. 456456
  6. Zugr5nd
  7. egerichtetd
  8. verichtetd
  9. '''
  10. """
  11. # Test the new slices.
  12. import strutils
  13. var mystr = "Abgrund"
  14. mystr[..1] = "Zu"
  15. mystr[4..4] = "5"
  16. type
  17. TEnum = enum e1, e2, e3, e4, e5, e6
  18. var myarr: array[TEnum, int] = [1, 2, 3, 4, 5, 6]
  19. myarr[e1..e3] = myarr[e4..e6]
  20. myarr[..e3] = myarr[e4..e6]
  21. for x in items(myarr): stdout.write(x)
  22. echo()
  23. var myarr2: array[0..5, int] = [1, 2, 3, 4, 5, 6]
  24. myarr2[0..2] = myarr2[3..5]
  25. for x in items(myarr2): stdout.write(x)
  26. echo()
  27. var myseq = @[1, 2, 3, 4, 5, 6]
  28. myseq[0..2] = myseq[^3 .. ^1]
  29. for x in items(myseq): stdout.write(x)
  30. echo()
  31. echo mystr
  32. mystr[4..4] = "u"
  33. # test full replacement
  34. mystr[.. ^2] = "egerichtet"
  35. echo mystr
  36. mystr[0..2] = "ve"
  37. echo mystr
  38. var s = "abcdef"
  39. s[1 .. ^2] = "xyz"
  40. assert s == "axyzf"