In the Go programming language, a rune is a basic data type designed to store a Unicode code point.
Questions tagged [rune]
58 questions
1
vote
1 answer
Golang Illegal rune literal error when splitting string
I am trying to split string based on split function in golang. But getting illegal rune literal error for r == '/--/' && r == '/-iN-/' && r == '/--/'
func Split(r rune) bool {
return r == '/--/' && r == '/-iN-/' && r == '/--/'
}

sjsri
- 63
- 1
- 8
1
vote
2 answers
Creating a substring in go creates a new kind of symbol
I am comparing strings and there is the following:
Please note that the " in front of NEW are different.
Now when calling my function like this:
my_func(a[18:], b[18:])
The resulting strings are surprisingly:
What do I have to do to cut this…

Beginner
- 5,277
- 6
- 34
- 71
1
vote
1 answer
How to convert a fixed-length array of hexadecimal runes to a single integer
Given an array of runes which is a string encoded in hexadecimal, how can I convert it to a single integer. For example:
var digits [8]rune = "00000010"
magicFunction(digits)
// gives 16
var digits2 [8]rune = "deadbeef"
magicFunction(digits2)
//…

pxeger
- 148
- 1
- 12
1
vote
1 answer
Golang runes in string or how to convert?
I have a string which contains following text.
\xD0\xA4\xD0\xB5\xD0\xB4\xD0\xBE\xD1\x80\xD0\xBE\xD0\xB2
It is not a literal. In string it's stored as separate characters like this ['\','x','D','0','\','x','A','4',...]
How to convert this string to…

Anton Globa
- 133
- 6
1
vote
1 answer
How to retrieve the first “complete” character of a []rune?
I am trying to write a function
func Anonymize(name string) string
that anonymizes names. Here are some examples of pairs of input and output so you get an idea of what it is supposed to do:
Müller → M.
von der Linden → v. d. L.
Meyer-Schulze →…

fuz
- 88,405
- 25
- 200
- 352
1
vote
2 answers
Iterate over 2 strings in go
I want to compare 2 strings rune-by-rune to see which one comes first in an arbitrary alphabetical order.
Right now I have this implementation which stores in map[rune]int a mapping representing the order of letters in my alphabet.
I have this…

Félix Cantournet
- 1,941
- 13
- 17
1
vote
2 answers
Building an ngram frequency table and dealing with multibyte runes
I am currently learning Go and am making a lot of progress. One way I do this is to port past projects and prototypes from a prior language to a new one.
Right now I am busying myself with a "language detector" I prototyped in Python a while ago.…

Wilhelm Murdoch
- 1,806
- 1
- 22
- 42
0
votes
1 answer
Inactivate emacs-lisp % format specifier
Using emacs-lisp I want to identify the word under point, specifically I want to be able to identify hoon runes. Runes are digraphs like ?=, /+, $-. Standard emacs lisp functions like 'thing-at-point', 'current-word' work fine for most runes except…

Mortimer Cladwell
- 25
- 4
0
votes
1 answer
C# Tamil Runes: How to get the correct number of Tamil letters
I'm trying to figure out how to handle filenames in Tamil. I need to shorten them like this:
"foobar.gif" -> "foo...gif".
I've learned today that some languages use more than one char to represent a letter and I discovered that C# has the Rune…

Niels Bosma
- 11,758
- 29
- 89
- 148
0
votes
1 answer
text/scanner hangs with IsIdentRune
If I have this code:
package main
import (
"strings"
"text/scanner"
)
func main() {
src := strings.NewReader("hello\nworld\n")
var s scanner.Scanner
s.Init(src)
s.IsIdentRune = func(ch rune, i int) bool {
return ch != '\n'
…
user17894590
0
votes
1 answer
string(int), string(int32) and string([]int32) are all valid but string([]int) is invalid - what's the rationale here?
(I'm using Go 1.14.6.)
The following statements would all output the char a
Println(string(int(97) ) )
Println(string(int32(97) ) )
Println(string([]int32{97} ) )
But
Println(string([]int{97} ) )
would cause compile error
cannot convert []int…

pynexj
- 19,215
- 5
- 38
- 56
0
votes
1 answer
How to rewind in Go's text/scanner?
I am using text/scanner package to parse some arbitrary expressions. I am currently trying to implement a not in option, that is, if the current identifier is not, and the next is in, parse it using function notin(left, right), and otherwise we…

GManz
- 1,548
- 2
- 21
- 42
0
votes
1 answer
Convert Go rune to string
I am trying to convert s := '{"selector:"{"Status":"open"}"}' to type string, as I need to pass this as an argument to a query using GetQueryResult().
I have tried UnescapeString, it only accepts string as argument:
fmt.Println("args "…

Harshitha C
- 65
- 1
- 8
-1
votes
1 answer
Go string appears shorter than it's first rune
I was running some fuzzing on my code and it found a bug. I have reduced it down to the following code snippet and I cannot see what is wrong.
Given the string
s := string("\xc0")
The len(s) function returns 1. However, if you loop through the…

Daniel Whitford
- 19
- 4
-1
votes
2 answers
Splitting a rune correctly in golang
I'm wondering if there is an easy way, such as well known functions to handle code points/runes, to take a chunk out of the middle of a rune slice without messing it up or if it's all needs to coded ourselves to get down to something equal to or…

Reg
- 67
- 7