diff --git a/examples.txt b/examples.txt index 5776e1d..b329953 100644 --- a/examples.txt +++ b/examples.txt @@ -42,7 +42,7 @@ WaitGroups Panic Defer Функции коллекции (Collection Functions) -String Functions +Строковые функции (String Functions) String Formatting Regular Expressions JSON diff --git a/examples/string-functions/string-functions.go b/examples/string-functions/string-functions.go index 676e904..4cc6560 100644 --- a/examples/string-functions/string-functions.go +++ b/examples/string-functions/string-functions.go @@ -1,6 +1,6 @@ -// The standard library's `strings` package provides many -// useful string-related functions. Here are some examples -// to give you a sense of the package. +// Стандартная библиотека пакета `strings` предоставляет +// множество удобных функций для работы со строками. Вот +// некоторые из них. package main @@ -9,19 +9,18 @@ import ( s "strings" ) -// We alias `fmt.Println` to a shorter name as we'll use -// it a lot below. +// Создаем алиас для функции `fmt.Println`, т.к. далее мы будем +// часто вызывать эту функцию. var p = fmt.Println func main() { - // Here's a sample of the functions available in - // `strings`. Since these are functions from the - // package, not methods on the string object itself, - // we need pass the string in question as the first - // argument to the function. You can find more - // functions in the [`strings`](http://golang.org/pkg/strings/) - // package docs. + // Данные функции доступны в пакете `strings`. Обратите внимание, + // что все эти функции из пакета, а не методы строковых объектов. + // Это означает, что нам необходимо передать первым аргументом + // функции, строку, над которой мы производим операцию. Вы можете + // найти больше строковых функций в [`официальной документации + // к пакету`](http://golang.org/pkg/strings/). p("Contains: ", s.Contains("test", "es")) p("Count: ", s.Count("test", "t")) p("HasPrefix: ", s.HasPrefix("test", "te")) @@ -36,16 +35,17 @@ func main() { p("ToUpper: ", s.ToUpper("test")) p() - // Not part of `strings`, but worth mentioning here, are - // the mechanisms for getting the length of a string in - // bytes and getting a byte by index. + // Примеры ниже не относятся к пакету `strings`, но о них + // стоит упомянуть - это механизмы для получения длины + // строки и получение символа по индексу. p("Len: ", len("hello")) p("Char:", "hello"[1]) } -// Note that `len` and indexing above work at the byte level. -// Go uses UTF-8 encoded strings, so this is often useful -// as-is. If you're working with potentially multi-byte -// characters you'll want to use encoding-aware operations. -// See [strings, bytes, runes and characters in Go](https://blog.golang.org/strings) -// for more information. +// Обратите внимание, что `len` и индексация выше работают на +// уровне байтов. Go использует строки в кодировке UTF-8, так +// что это часто полезно как есть. Если вы работаете с +// потенциально многобайтовыми символами, вам нужно использовать +// операции с кодировкой. Смотрите [строки, байты, руны и символы +// в Go](https://blog.golang.org/strings) для получения дополнительной +// информации.