split(a,".") 3-element Array{SubStr-6ren">
gpt4 book ai didi

julia - 仅按第一次出现的分隔符来分割字符串

转载 作者:行者123 更新时间:2023-12-03 15:40:08 25 4
gpt4 key购买 nike

我想通过.的第一次出现来拆分字符串。

julia> a = "x1.y1.xyz22"
"x1.y1.xyz22"

julia> split(a,".")
3-element Array{SubString{String},1}:
"x1"
"y1"
"xyz22"

如何在Julia中将字符串仅拆分一次才能获得:
“x1”
“y1.xyz22”?

先感谢您,

最佳答案

使用limit关键字。

对于此类问题,您还可以有效地使用内联文档。.只需在控制台中键入?split(或任何其他函数或类型)即可检索该函数,其参数和常用用法示例的详细说明。在这种情况下:

help?> split
search: split splitext splitdir splitpath splitdrive rsplit splice! displaysize @specialize @nospecialize

split(str::AbstractString, dlm; limit::Integer=0, keepempty::Bool=true)
split(str::AbstractString; limit::Integer=0, keepempty::Bool=false)

Split str into an array of substrings on occurrences of the delimiter(s) dlm. dlm can be any of the formats allowed by findnext's first argument (i.e. as a string, regular expression or a function), or as a single character or collection of characters.

If dlm is omitted, it defaults to isspace.

The optional keyword arguments are:

• limit: the maximum size of the result. limit=0 implies no maximum (default)

• keepempty: whether empty fields should be kept in the result. Default is false without a dlm argument, true with a dlm argument.

See also rsplit.

Examples
≡≡≡≡≡≡≡≡≡≡

julia> a = "Ma.rch"
"Ma.rch"

julia> split(a,".")
2-element Array{SubString{String},1}:
"Ma"
"rch"

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Splits an HyperRectangle into two along an axis at a given location.

关于julia - 仅按第一次出现的分隔符来分割字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59922743/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com