Recent Entries 7
- snippet critical 112d agoHow to get the last X Characters of a Golang String?If I have the string "12121211122" and I want to get the last 3 characters (e.g. "122"), is that possible in Go? I've looked in the `string` package and didn't see anything like `getLastXcharacters`.
- snippet critical 112d agoHow to index characters in a Golang string?How to get an "E" output rather than 69? ``` package main import "fmt" func main() { fmt.Print("HELLO"[1]) } ``` Does Golang have function to convert a char to byte and vice versa?
- snippet critical 112d agoHow to get the number of characters in a stringHow can I get the number of characters of a string in Go? For example, if I have a string `"hello"` the method should return `5`. I saw that `len(str)` returns the number of bytes and not the number of characters so `len("£")` returns 2 instead of 1 because £ is encoded with two bytes in UTF-8.
- pattern critical 112d agoFor every character in stringHow would I do a for loop on every character in string in C++?
- pattern critical 112d agoReplace a character at a specific index in a string?I'm trying to replace a character at a specific index in a string. What I'm doing is: ``` String myName = "domanokz"; myName.charAt(4) = 'x'; ``` This gives an error. Is there any method to do this?
- pattern critical 112d agoWhat is the easiest/best/most correct way to iterate through the characters of a string in Java?Some ways to iterate through the characters of a string in Java are: - Using `StringTokenizer`? - Converting the `String` to a `char[]` and iterating over that. What is the easiest/best/most correct way to iterate?
- pattern critical 112d agoRepeat a string in JavaScript a number of timesIn Perl I can repeat a character multiple times using the syntax: ``` $a = "a" x 10; // results in "aaaaaaaaaa" ``` Is there a simple way to accomplish this in Javascript? I can obviously use a function, but I was wondering if there was any built in approach, or some other clever technique.