Golang's Strings Bag

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Only the use of partial function methods is listed:

Too much.......

Package Mainimport ("FMT"    "Strings"Func Main () {count computes the non-overlapping number of Sep in S, func Count (S, substrstring)int{s:="Hello, super brother."Count l occurrences N:= Strings. Count (S,"L") fmt. PRINTLN (n)//2If substr is empty, returns the number of characters in S +1N=strings. Count (S,"") fmt. PRINTLN (n) Contains determines whether the string s contains substrings substr func Contains (S, substrstring)BOOL{substr writes nothing, returns True if present returns True, otherwise false s:="Hello, super brother!!"B:= Strings. Contains (s),"!") fmt. Println (b)//trueb = Strings. Contains (s),"@")//falseFMT. Println (b) B=strings. Contains (s),"") fmt. Println (b) Containsany determines whether the string s contains any of the characters in chars if char is null, returns false Func Containsany (s, charsstring)BOOL{s:="Hello, super brother."B:= Strings. Containsany (s),"ABC") fmt. Println (b)//falseB=strings. Containsany (s),"def")//trueFMT. Println (b) B=strings. Containsany (s),"")//falseFMT. Println (b) Containsrune determines whether the string s contains a character R rune cannot be null, exists true, otherwise false func Containsrune (sstring, R Rune)BOOL{s:="Hello, super brother!"B:= Strings. Containsrune (s),'\ n') fmt. Println (b)//falseb = Strings. Containsrune (s),'Super') fmt. Println (b)//trueb = Strings. Containsrune (s),'o') fmt. Println (b)//trueIndexany Returns the position (index) of the first occurrence of any character in the string chars in the string s .-1, chars is also returned as null-1func strings. Indexany () s:="Hello, super brother! Hello!"B:= Strings. Indexany (s),"ABC") fmt. Println (b)//-1b = Strings. Indexany (s),"") fmt. Println (b)//-1b = Strings. Indexany (s),"Super") fmt. Println (b) Lastindexany returns the last occurrence of any one of the string s in the string chars.-1, chars is also returned as null-1func Lastindexany (S, charsstring)int{s:="Hello, the world! Hello! "B:=strings. Lastindexany (s),"ABC") fmt. Println (b)//-1B=strings. Lastindexany (s),"World") fmt. Println (b)//6 Last occurrence of index positionB=strings. Lastindexany (s),"") fmt. Println (b)//-1}

Comparison of the whole is Golang Chinese network: https://studygolang.com/articles/5769

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.