DXL 中的字符串拆分
我有一个字符串
例如:“我们更喜欢可以回答的问题;而不仅仅是讨论”
现在我想将此字符串与“;”分开 喜欢 我们更喜欢可以回答的问题 和 不仅仅讨论了
这在 DXL 中是否可能。
我正在学习DXL,所以我不知道我们是否可以分开。
注意:这不是家庭作业。
I have a string
Ex: "We prefer questions that can be answered; not just discussed "
now i want to split this string from ";"
like
We prefer questions that can be answered
and
not just discussed
is this possible in DXL.
i am learning DXL, so i don't have any idea whether we can split or not.
Note : This is not a home work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我很抱歉破坏了这篇文章。 作为 DXL 新手,我花了一些时间来应对同样的挑战。 我注意到可用的实现具有不同的“拆分”字符串规范。 由于喜欢 Ruby 语言,我错过了一个至少接近 String#split 的 Ruby 版本。
也许我的发现对任何人都有帮助。
以下是变体 A: niol 实现的功能比较
为了消除结构差异,所有实现都在函数中实现,返回
Skip
列表或Array
分割结果
注意,所有实现都会返回不同的结果,具体取决于它们对“分割”的定义:
string
mellow Yellow
;string
now's the time< /code>; delimiter
string
1,2,,3,4,,
delimiter,
时机
分割字符串
1,2 ,,3,4,,
与模式,
在我的机器上运行 10000 次给出以下计时:不幸的是,我的实现 D 是最慢的。 令人惊讶的是,C 的正则表达式实现非常快。
源代码
I'm sorry for necroing this post. Being new to DXL I spent some time with the same challenge. I noticed that the implementations available on the have different specifications of "splitting" a string. Loving the Ruby language, I missed an implementation which comes at least close to the Ruby version of String#split.
Maybe my findings will be helpful to anybody.
Here's a functional comparison of
To eliminate structural difference, all implementations were implemented in functions, returning a
Skip
list or anArray
.Splitting results
Note that all implementations return different results, depending on their definition of "splitting":
string
mellow yellow
; delimiterello
string
now's the time
; delimiterstring
1,2,,3,4,,
; delimiter,
Timing
Splitting the string
1,2,,3,4,,
with the pattern,
for 10000 times on my machine gives these timings:Unfortunately, my implementation D is the slowest. Surprisingly, the regular expressions implementation C is pretty fast.
Source code
我能想到的快速连接和分离。 接缝工作正常。
Quick join&split I could come up with. Seams to work okay.
如果您只拆分字符串一次,我会这样做:
您还可以使用正则表达式,请参阅 DXL 参考手册。 如果你想用多个分隔符分割字符串,例如 str = "this ; is an;example" ,那么最好使用正则表达式
If you only split the string once this is how I would do it:
You could also use regular expressions refer to the DXL reference manual. It would be better to use regular expressions if you want to split up the string by multiple delimiters such as str = "this ; is an;example"
实际上有效:
如果字符串中不存在分隔符,此解决方案将根据需要多次拆分,或者不拆分。
这就是我使用的而不是传统的“split”命令。
它实际上跳过了数组的创建,只是循环遍历数组中的每个字符串并对每个字符串调用“someFunction”。
抱歉,破坏了旧帖子; 我只是觉得其他答案没有用。
ACTUALLY WORKS:
This solution will split as many times as needed, or none, if the delimiter doesn't exist in the string.
This is what I have used instead of a traditional "split" command.
It actually skips the creation of an array, and just loops through each string that would be in the array and calls "someFunction" on each of those strings.
Sorry for necroing an old post; I just didn't find the other answers useful.
也许有人也会发现这种融合解决方案很方便。 它根据分隔符分割 Skip 中的字符串,分隔符的长度实际上可以大于 1。
Perhaps someone would find handy this fused solution as well. It splits string in Skip, based on delimiter, which can actually have length more then one.
我尝试过这个并为我解决了......
I tried this out and worked out for me...
这是一个更好的实现。 这是通过搜索关键字来递归分割字符串。
Here is a better implementation. This is a recursive split of the string by searching a keyword.
上述解决方案都不适合我,所以我写了自己的:
结果(countSkip 也是 custum):
输出:
None of above solutions worked for me, so I wrote my own:
Results (countSkip is custum too):
Output: