Get the first letters of a string
Hello,
Let's say that I have the string "tyranitar". With string[X], I can get the letter that I want, but is there a method or a fast way to get the first X chars of a string ? For exemple if I want "tyrani", how can I ask to substract from [0] to [6] ?
Thanks
12 Replies
"Substract from 0 to 6"...?
You mean get a range of letters?
Angius#1586
REPL Result: Success
Result: string
Compile: 352.181ms | Execution: 45.632ms | React with ❌ to remove this embed.
Doombox#1389
REPL Result: Success
Compile: 405.693ms | Execution: 25.563ms | React with ❌ to remove this embed.
damnit, semicolon every time
Use the range operator, less typing
But sure,
.Substring()
also workstrue, substring is the OG way
a time before C#8
Thanks !
was curious if either was faster, not really
different implementations but it's such a simple op that it ends up the same anyways
this benchmark is completely noise, the range operator literally calls Substring
makes sense
you can also tell that it's noise because the confidence intervals are overlapping (718 ± 12 overlaps 699 ± 17)
which means that the difference is not statistically significant