From f2b4ff5e68e1a46179bbd109505a41ee6b5e8972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Tue, 3 Oct 2017 21:34:15 +0200 Subject: [PATCH] Add documentation of SubString (#23957) * Add documentation of SubString `SubString` first appears in the section of regular expressions, but it is not mentioned earlier. I suggest to add documentation of `SubString` as it is returned by several functions from the standard library. * moved to basics section * improved the description --- doc/src/manual/strings.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/doc/src/manual/strings.md b/doc/src/manual/strings.md index a5b5746975455..466d4f256c65f 100644 --- a/doc/src/manual/strings.md +++ b/doc/src/manual/strings.md @@ -228,6 +228,24 @@ julia> str[6:6] The former is a single character value of type `Char`, while the latter is a string value that happens to contain only a single character. In Julia these are very different things. +Range indexing makes a copy of the selected part of the original string. +Alternatively, it is possible to create a view into a string using the type `SubString`, +for example: + +```jldoctest +julia> str = "long string" +"long string" + +julia> substr = SubString(str, 1, 4) +"long" + +julia> typeof(substr) +SubString{String} +``` + +Several standard functions like [`chop`](@ref), [`chomp`](@ref) or [`strip`](@ref) +return a `SubString`. + ## Unicode and UTF-8 Julia fully supports Unicode characters and strings. As [discussed above](@ref man-characters), in character