2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Golang で string 型の enum 的なもの

Last updated at Posted at 2019-10-25

やりたいこと :relieved:

連続する数値の文字列

const (
	zeroStr = "0" 
	oneStr = "1"
	twoStr = "2"
	threeStr = "3"
	fourStr = "4"
	fiveStr = "5"
)

をintみたく:point_down:iotaで自動採番したい。

const (
	zeroInt int = iota
	oneInt
	twoInt
	threeInt
	fourInt
	fiveInt
)

やったこと :angel:

asciiにしてあげる

const (
	zeroStr = string(iota + '0') // '0' == 0x30
	oneStr
	twoStr
	threeStr
	fourStr
	fiveStr
)

以上です:relaxed:

2
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?