Advertisement
cydside

Delete all superfluous spaces from a string

Apr 23rd, 2023 (edited)
1,154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.38 KB | None | 0 0
  1. //______________________________________________________________________________
  2.  
  3. // ZapBlanks elimina tutti i spazi superflui da una stringa.
  4. func ZapBlanks(text string) string {
  5.     borders := regexp.MustCompile(`^[\s\p{Zs}]+|[\s\p{Zs}]+$`)
  6.     inner := regexp.MustCompile(`[\s\p{Zs}]{2,}`)
  7.     f := borders.ReplaceAllString(text, "")
  8.     f = inner.ReplaceAllString(f, " ")
  9.  
  10.     return f
  11. }
  12.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement