GithubHelp home page GithubHelp logo

Comments (6)

shirou avatar shirou commented on June 9, 2024

Hmm, I am not so good at English. Could you tell me what kind of Function name is better for the purpose?

from gopsutil.

gwind avatar gwind commented on June 9, 2024

You are too modest. :-)

a poor example:

package main

import (
    "fmt"
    "strings"
)

// Check the target string slice containes src or not
func StringsHas(target []string, src string) bool {
    for _, t := range target {
        if strings.TrimSpace(t) == src {
            return true
        }
    }
    return false
}

// Does src in any string of the target string slice
func StringsFind(target []string, src string) bool {
    for _, t := range target {
        if strings.Index(t, src) >= 0 {
            return true
        }
    }
    return false
}

func main() {
    v := []string{
        "hello, c",
        "hello, unix",
        "hello, gnu",
        "hello, linux",
        "hello, go",
    }

    test_data := []string{
        "hello, c",
        "unix",
        "Java",
    }
    for _, s := range test_data {
        fmt.Printf("StringsHas(\"%s\", v) = %t\n", s, StringsHas(v, s))
        fmt.Printf("StringsFind(\"%s\", v) = %t\n", s, StringsFind(v, s))
    }
}

from gopsutil.

shirou avatar shirou commented on June 9, 2024

Thank you for the suggestion!

golang has the method called strings.Contains to check strings has the substr or not.

If I change your StringsFind to use strings.Contains, changing the name to StringsContains is acceptable?

Sorry for annoying you. But I can not understand well such a nuances. Really.

from gopsutil.

gwind avatar gwind commented on June 9, 2024

Yes, it's good. I've missed the strings.Contains .

from gopsutil.

shirou avatar shirou commented on June 9, 2024

I commit the change at b5ffc22. If I have miss understanding, please re-open this issue.

I am very appriciate to have discussion with you. Thank you.

from gopsutil.

gwind avatar gwind commented on June 9, 2024

It's a nice job, thanks for your share.

from gopsutil.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.