Socket
Socket
Sign inDemoInstall

github.com/srfrog/go-strarr

Package Overview
Dependencies
0
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/srfrog/go-strarr

Various operations for string slices for Go Package strarr is a collection of functions to manipulate string arrays/slices. Some functions were adapted from the strings package to work with string slices, other were ported from PHP 'array_*' function equivalents. This example shows basic usage of various functions by manipulating the array 'arr'.


Version published

Readme

Source

Go-StrArr GoDoc

Various operations for string slices for Go

Go-StrArr is a collection of functions that operate on string slices. Most are functions from package strings that have been adapted to work with string slices, and some were ported from PHP array_* functions.

Features

  • Using a thin layer of idiomatic Go; correctness over performance.
  • Provide most basic array-ish operations: index, trim, filter, map
  • Some PHP favorites like: pop, push, shift, unshift, shuffle, etc...
  • Non-destructive returns (won't alter original slice), except for explicit tasks.
  • The perfect companion to work with net/http headers!

Installation

Using "go get":

go get github.com/codehack/go-strarr

Then import:

import ("github.com/codehack/go-strarr")

Example

package main

import(
   "github.com/codehack/go-strarr"
   "fmt"
)

// This example shows basic usage of various functions by manipulating
// the array 'arr'.
func main() {
   arr := []string{"Go", "nuts", "for", "Go"}

   foo := strarr.Repeat("Go",3)
   fmt.Println(foo)

   fmt.Println(strarr.Count(arr, "Go"))

   fmt.Println(strarr.Index(arr, "Go"))
   fmt.Println(strarr.LastIndex(arr, "Go"))

   if strarr.Contains(arr, "nuts") {
      arr = strarr.Replace(arr, []string{"Insanely"})
   }
   fmt.Println(arr)

   str := strarr.Shift(&arr)
   fmt.Println(str)
   fmt.Println(arr)

   strarr.Unshift(&arr, "Really")
   fmt.Println(arr)

   fmt.Println(strarr.ToUpper(arr))
   fmt.Println(strarr.ToLower(arr))
   fmt.Println(strarr.ToTitle(arr))

   fmt.Println(strarr.Trim(arr,"Really"))
   fmt.Println(strarr.Filter(arr,"Go"))

   fmt.Println(strarr.Diff(arr,foo))
   fmt.Println(strarr.Intersect(arr,foo))

   fmt.Println(strarr.Rand(arr,2))

   fmt.Println(strarr.Reverse(arr))
}

See the testing source strarr_test.go for more examples.

Documentation

The full code documentation is located at GoDoc:

http://godoc.org/github.com/codehack/go-strarr

Go-StrArr is Copyright (c) 2014 Codehack. Published under MIT License

Go nuts for Go!

FAQs

Last updated on 10 Jun 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc