简体   繁体   English

APL / APLX - 拆分字符串

[英]APL/APLX - Splitting a string

I have a single string (the result from reading in a paragraph of text) that I'd like to split into an array of words. 我有一个字符串(读取文本段落的结果),我想分成一个单词数组。 I'd be splitting the string on every space. 我会在每个空间上分割字符串。 This seems like it should be simple but I can't seem to find out a way to accomplish this. 这似乎应该很简单,但我似乎无法找到实现这一目标的方法。

It's worth noting that I'm using APLX, so I do have the option of importing a Ruby function, but I'd much rather stick to APL. 值得注意的是我正在使用APLX,所以我确实可以选择导入Ruby函数,但我更倾向于坚持使用APL。

There are many different way to tackle this. 有许多不同的方法可以解决这个问题。 Most often I use the following dfn in Dyalog APL : 大多数情况下,我在Dyalog APL中使用以下dfn:

penclose←{⎕ML←3 ⋄ ⍺←↑,⍵ ⋄ (~⍵∊⍺)⊂,⍵ } ⍝ separator as ⍺ or ⍵[1]

I'm not sure whether APLX has dfns, so a more "traditional" style would be: 我不确定APLX是否有dfns,所以更“传统”的风格是:

∇ R←penclose R;a
   ⍝ Partitioned enclose of text vector with separator in R[1]
   ⍝ ⎕ML←3  ⍝ Dyalog-specific to make ⊂ APL2-compatible...
 a←1↑R ⋄ R←(~R∊a)⊂R
∇

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM