print_Fmt.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package utils
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. // 定义一个自定义类型
  7. type MyFmt struct {
  8. str string
  9. }
  10. // 实现 Stringer 接口
  11. func (m MyFmt) String() string {
  12. return fmt.Sprintf("---------------------%v----------------------", m.str)
  13. }
  14. func (m MyFmt) SetStr(str string) string {
  15. m.str = str
  16. return m.str
  17. }
  18. func SplitFileLocal(sql string) []string {
  19. fmt.Println("SplitFileLocal.sql = ", sql)
  20. var fileLocal []string
  21. var f func(sql string)
  22. f = func(sql string) {
  23. // 找到第一个<的位置
  24. semicolonIndex := strings.Index(sql, "<")
  25. if semicolonIndex != -1 {
  26. lastIndex := strings.LastIndex(sql, "<")
  27. fileLocal = append(fileLocal, sql[lastIndex+2:])
  28. fmt.Println(" rear[lastIndex+2:]", sql[lastIndex+2:])
  29. sql = sql[:lastIndex]
  30. fmt.Println(" sql[:lastIndex]", sql[:lastIndex])
  31. f(sql)
  32. } else {
  33. fmt.Println("未找到<。")
  34. }
  35. }
  36. f(sql)
  37. for i, j := 0, len(fileLocal)-1; i < j; i, j = i+1, j-1 {
  38. fileLocal[i], fileLocal[j] = fileLocal[j], fileLocal[i]
  39. }
  40. fmt.Printf("\nfileLocal排序后:%v\n", fileLocal)
  41. return fileLocal
  42. }