@@ -628,3 +628,93 @@ func ExampleToUpperSpecial() {
628
628
// Original : ahoj vývojári golang
629
629
// ToUpper : AHOJ VÝVOJÁRİ GOLANG
630
630
}
631
+
632
+ func ExampleLines () {
633
+ text := []byte ("Hello\n World\n Go Programming\n " )
634
+ for line := range bytes .Lines (text ) {
635
+ fmt .Printf ("%q\n " , line )
636
+ }
637
+
638
+ // Output:
639
+ // "Hello\n"
640
+ // "World\n"
641
+ // "Go Programming\n"
642
+ }
643
+
644
+ func ExampleSplitSeq () {
645
+ s := []byte ("a,b,c,d" )
646
+ for part := range bytes .SplitSeq (s , []byte ("," )) {
647
+ fmt .Printf ("%q\n " , part )
648
+ }
649
+
650
+ // Output:
651
+ // "a"
652
+ // "b"
653
+ // "c"
654
+ // "d"
655
+ }
656
+
657
+ func ExampleSplitAfterSeq () {
658
+ s := []byte ("a,b,c,d" )
659
+ for part := range bytes .SplitAfterSeq (s , []byte ("," )) {
660
+ fmt .Printf ("%q\n " , part )
661
+ }
662
+
663
+ // Output:
664
+ // "a,"
665
+ // "b,"
666
+ // "c,"
667
+ // "d"
668
+ }
669
+
670
+ func ExampleFieldsSeq () {
671
+ text := []byte ("The quick brown fox" )
672
+ fmt .Println ("Split byte slice into fields:" )
673
+ for word := range bytes .FieldsSeq (text ) {
674
+ fmt .Printf ("%q\n " , word )
675
+ }
676
+
677
+ textWithSpaces := []byte (" lots of spaces " )
678
+ fmt .Println ("\n Split byte slice with multiple spaces:" )
679
+ for word := range bytes .FieldsSeq (textWithSpaces ) {
680
+ fmt .Printf ("%q\n " , word )
681
+ }
682
+
683
+ // Output:
684
+ // Split byte slice into fields:
685
+ // "The"
686
+ // "quick"
687
+ // "brown"
688
+ // "fox"
689
+ //
690
+ // Split byte slice with multiple spaces:
691
+ // "lots"
692
+ // "of"
693
+ // "spaces"
694
+ }
695
+
696
+ func ExampleFieldsFuncSeq () {
697
+ text := []byte ("The quick brown fox" )
698
+ fmt .Println ("Split on whitespace(similar to FieldsSeq):" )
699
+ for word := range bytes .FieldsFuncSeq (text , unicode .IsSpace ) {
700
+ fmt .Printf ("%q\n " , word )
701
+ }
702
+
703
+ mixedText := []byte ("abc123def456ghi" )
704
+ fmt .Println ("\n Split on digits:" )
705
+ for word := range bytes .FieldsFuncSeq (mixedText , unicode .IsDigit ) {
706
+ fmt .Printf ("%q\n " , word )
707
+ }
708
+
709
+ // Output:
710
+ // Split on whitespace(similar to FieldsSeq):
711
+ // "The"
712
+ // "quick"
713
+ // "brown"
714
+ // "fox"
715
+ //
716
+ // Split on digits:
717
+ // "abc"
718
+ // "def"
719
+ // "ghi"
720
+ }
0 commit comments