Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stringx candidate #12

Open
wklken opened this issue Nov 26, 2021 · 3 comments
Open

stringx candidate #12

wklken opened this issue Nov 26, 2021 · 3 comments

Comments

@wklken
Copy link
Collaborator

wklken commented Nov 26, 2021

// TruncateBytes truncate []byte to specific length
func TruncateBytes(content []byte, length int) []byte {
	if len(content) > length {
		return content[:length]
	}
	return content
}

// TruncateBytesToString ...
func TruncateBytesToString(content []byte, length int) string {
	s := TruncateBytes(content, length)
	return string(s)
}

@wklken
Copy link
Collaborator Author

wklken commented Mar 14, 2022

  • RepeatN(s string, n int) string use strings.Builder

  • RepeatChar(c rune, n int) string use strings.Builder

  • IsNumeric(s string) bool use unicode.IsDigit(v)

  • IsAlphanumeric(s string) bool use isAlphanumeric(v)

  • IsAlpha(s string) bool use unicode.IsLetter(v)

  • ContainsAnySubstrings(s string, subs []string) bool use strings.Contains

  • padLeft / padRight to fixed length with specific char

@wklken
Copy link
Collaborator Author

wklken commented Mar 14, 2022

SplitIntoInt64s(s string) ([]int64, error)
JoinInt64s(l []int64) string

@wklken
Copy link
Collaborator Author

wklken commented Nov 10, 2022

  • SplitInt 1,2,3,4 to []int{1,2,3,4}
  • Join []string{"a", "b"} to a,b
  • SubString

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant