Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rym-util
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhengqiuyun
rym-util
Commits
fc0c8f31
Commit
fc0c8f31
authored
Aug 16, 2022
by
zhengqiuyun86
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
初始化
parent
c975ece2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
61 deletions
+4
-61
StringUtil.go
util/StringUtil.go
+0
-61
StringUtil_test.go
util/StringUtil_test.go
+4
-0
No files found.
util/StringUtil.go
View file @
fc0c8f31
package
util
package
util
import
(
import
(
"encoding/json"
"math/rand"
"math/rand"
"strconv"
"strings"
"strings"
)
)
...
@@ -18,65 +16,6 @@ func FandomString(strlen int) string {
...
@@ -18,65 +16,6 @@ func FandomString(strlen int) string {
return
string
(
result
)
return
string
(
result
)
}
}
// Strval 获取变量的字符串值
// 浮点型 3.0将会转换成字符串3, "3"
// 非数值或字符类型的变量将会被转换成JSON格式字符串
func
Strval
(
value
interface
{})
string
{
// interface 转 string
var
key
string
if
value
==
nil
{
return
key
}
switch
value
.
(
type
)
{
case
float64
:
ft
:=
value
.
(
float64
)
key
=
strconv
.
FormatFloat
(
ft
,
'a'
,
-
1
,
64
)
case
float32
:
ft
:=
value
.
(
float32
)
key
=
strconv
.
FormatFloat
(
float64
(
ft
),
'a'
,
-
1
,
64
)
case
int
:
it
:=
value
.
(
int
)
key
=
strconv
.
Itoa
(
it
)
case
uint
:
it
:=
value
.
(
uint
)
key
=
strconv
.
Itoa
(
int
(
it
))
case
int8
:
it
:=
value
.
(
int8
)
key
=
strconv
.
Itoa
(
int
(
it
))
case
uint8
:
it
:=
value
.
(
uint8
)
key
=
strconv
.
Itoa
(
int
(
it
))
case
int16
:
it
:=
value
.
(
int16
)
key
=
strconv
.
Itoa
(
int
(
it
))
case
uint16
:
it
:=
value
.
(
uint16
)
key
=
strconv
.
Itoa
(
int
(
it
))
case
int32
:
it
:=
value
.
(
int32
)
key
=
strconv
.
Itoa
(
int
(
it
))
case
uint32
:
it
:=
value
.
(
uint32
)
key
=
strconv
.
Itoa
(
int
(
it
))
case
int64
:
it
:=
value
.
(
int64
)
key
=
strconv
.
FormatInt
(
it
,
10
)
case
uint64
:
it
:=
value
.
(
uint64
)
key
=
strconv
.
FormatUint
(
it
,
10
)
case
string
:
key
=
value
.
(
string
)
case
[]
byte
:
key
=
string
(
value
.
([]
byte
))
default
:
newValue
,
_
:=
json
.
Marshal
(
value
)
key
=
string
(
newValue
)
}
return
key
}
func
IsEmpty
(
s
*
string
)
bool
{
func
IsEmpty
(
s
*
string
)
bool
{
return
s
==
nil
||
*
s
==
""
return
s
==
nil
||
*
s
==
""
}
}
...
...
util/StringUtil_test.go
View file @
fc0c8f31
...
@@ -10,3 +10,7 @@ func TestContainsForSplitComma(t *testing.T) {
...
@@ -10,3 +10,7 @@ func TestContainsForSplitComma(t *testing.T) {
b
:=
"14"
b
:=
"14"
fmt
.
Printf
(
"%s是否包含在[%s]中:%v"
,
a
,
b
,
ContainsForSplitComma
(
b
,
a
))
fmt
.
Printf
(
"%s是否包含在[%s]中:%v"
,
a
,
b
,
ContainsForSplitComma
(
b
,
a
))
}
}
func
TestStrval
(
t
*
testing
.
T
)
{
fmt
.
Printf
(
"转换内容:%s"
,
GetInterfaceToString
(
3.10
))
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment