Home > other >  The language data type conversion, a great god answers
The language data type conversion, a great god answers

Time:10-06

Can go language like c language implementation letters and ASCII swap?
If you can how to swap?
Like a string (80) can get P
But the letter how to convert the ASCII code?

CodePudding user response:

 
S:=string (80)
//string can only first array, and then according to the length of the array in each element
Arr=(byte []) (s)
Num:=arr [0]

CodePudding user response:

 
S:='P'
B:=(byte) (s)
FMT. Println (b)

CodePudding user response:

Please use the for range string try

CodePudding user response:

You can use a rune types, the code is as follows:
 
Var a rune='P'

FMT. Println (" a: ", a)
FMT. Println (" a: ", string (a))
FMT. Println (" a: ", string (80))




Results:
A: 80
A: P
A: P

CodePudding user response:

Single letter can use strconv. Atoi
String can use byte [] (STR)

CodePudding user response:

P:=FMT. Sprintf (" % c ", 80)
  • Related