9.10 用指定分隔符将字符串拆分为两段
使用“?”或“=”作为分隔符,将字符串分别拆分为两个字符串。
在某网站记载了用户访问的 URL,要查询使用频率最高的搜索条件。部分内容如下:
ID | User | Website |
---|---|---|
1 | Rebecca | https://github.com/search?q=How+to+study+java%3F |
2 | Ashley | https://github.com/search?q=report&type=Code |
3 | Rachel | https://github.com/search?q=bigdata&type=Repositories |
4 | Rachel | https://github.com/search?l=Python&q=bigdata&type=Repositories |
… | … | … |
使用函数 s.split(d) 的 @1 选项,找到第一个 d 即停止,即拆成两段。
脚本:
A | |
---|---|
1 | =T(“loginUrls.txt”) |
2 | =A1.(Website.split@1(“?”)(2)) |
3 | =A2.(~.split(“&”).select@1(like(~,“q=*”))) |
4 | =A3.(~.split@1(“=”)(2)) |
5 | =A4.group() |
6 | =A5.maxp(~.len())(1) |
A1 读取用户登录表
A2 使用 s.split() 函数的 @1 选项,根据第一个?拆分成两段
A3 参数按 & 拆分,选出 q=* 的条件,此条为用户搜索条件
A4 将搜索条件按 = 拆分两段,第二部分是搜索条件
A5 搜索条件分组
A6 选出数量最多的一组,即搜索次数最多的条件
运行结果:
Value |
---|
bigdata |