首页 \ 问答 \ “Split”返回多余的字符(“Split” returns redundant characters)

“Split”返回多余的字符(“Split” returns redundant characters)

我正在寻找一种实现拆分功能的简单方法。 这是我有的:

import Data.List
groupBy (\x y -> y /= ',') "aaa, bbb, ccc, ddd"

=> ["aaa",", bbb",", ccc",", ddd"]

这几乎是我想要的,除了分隔符“,”甚至是结果集中的额外空格这一事实。 我希望它是[ "aaa","bbb","ccc","ddd"]

那么最简单的方法是什么?


I'm looking for a simple way of implementing split function. Here is what I have:

import Data.List
groupBy (\x y -> y /= ',') "aaa, bbb, ccc, ddd"

=> ["aaa",", bbb",", ccc",", ddd"]

It's almost what I want except the fact that a delimiter "," and even an extra whitespace are in the result set. I'd like it to be ["aaa","bbb","ccc","ddd"]

So what is the simplest way to do that?


原文:https://stackoverflow.com/questions/24673416
更新时间:2023-09-14 21:09

最满意答案

var res = child.execSync("df -l | awk \'{t += $2} END {printf \"%d G\\n\", t / 2^20 + 0.5}\'");

作品,测试。

\n 。问题在于\n 。 它应该是\\n 。 您可以像这样调试任何shell任务: console.log(SHELL_COMMAND) ,然后手动运行输出字符串。

例如,这个:

var child = require('child_process');
var cmd = "df -l | awk '{t += $2} END {printf \"%d G\n\", t / 2^20 + 0.5}'";
console.log(cmd)
var res = child.execSync(cmd);

将在控制台中输出并尝试运行此操作:

df -l | awk '{t += $2} END {printf "%d G
", t / 2^20 + 0.5}'

这没有意义。


var res = child.execSync("df -l | awk \'{t += $2} END {printf \"%d G\\n\", t / 2^20 + 0.5}\'");

works, tested.

The problem was with \n. It should be \\n. You can debug any shell task like this: console.log(SHELL_COMMAND) and then mannually run output string.

For example, this:

var child = require('child_process');
var cmd = "df -l | awk '{t += $2} END {printf \"%d G\n\", t / 2^20 + 0.5}'";
console.log(cmd)
var res = child.execSync(cmd);

will output in console and try to run this:

df -l | awk '{t += $2} END {printf "%d G
", t / 2^20 + 0.5}'

which makes no sense.

相关问答

更多
  • 单引号和双引号之间的区别是shell问题, 而不是 grep问题。 在将参数传递给grep之前,它决定做或不做可变扩展。 由于参数的shell处理的最后一步是引用移除, grep甚至从不会看到引号。 变量扩展不是单引号和双引号之间的唯一区别。 shell还在双引号内进行命令替换和算术扩展。 例如: $ echo "$(date) and 2+2=$((2+2))" Tue Aug 5 18:52:39 PDT 2014 and 2+2=4 $ echo '$(date) and 2+2=$((2+2))' ...
  • 您将需要使用单引号,您希望双引号出现在字符串中(例如,为HTML属性),而不必转义它们,反之亦然。 除此之外,没有什么区别。 You'll want to use single quotes where you want double quotes to appear inside the string (e.g. for html attributes) without having to escape them, or vice versa. Other than that, there is no d ...
  • 在双引号之前,您需要在字符串中插入反斜杠: let sentence = "They said \"It's okay\", didn't they?" 现在sentence是: 他们说“没关系”,不是吗? 它被称为“转义”一个字符:你使用它的字面值,它不会被解释。 使用Swift 4,您可以选择使用不需要转义的文本文本的"""分隔符: let sentence = """ They said "It's okay", didn't they? Yes, "okay" is what they said. ...
  • var res = child.execSync("df -l | awk \'{t += $2} END {printf \"%d G\\n\", t / 2^20 + 0.5}\'"); 作品,测试。 \n 。问题在于\n 。 它应该是\\n 。 您可以像这样调试任何shell任务: console.log(SHELL_COMMAND) ,然后手动运行输出字符串。 例如,这个: var child = require('child_process'); var cmd = "df -l | awk '{ ...
  • web.config是XML,因此您需要将内部引号转义为" :
    你不能直接做。 为你的用例定义一个变量: with_items: "{{ result | json_query(myquery) }}" vars: myquery: "{{ val }}" 对不起,只是举例,但我没有意志力从你在问题中写下的内容中找出你想要的问题。 JSON查询章节还有另一个例子。 You can't do it directly. For your use case define a variable: with_items: "{{ result | json_query(my ...
  • 这个webpack插件将会在你的代码中进行插值 。 换句话说,它将在构建时将process.env.NODE_ENV替换为您所拥有的任何内容。 所以你的代码从console.log(process.env.NODE_ENV)到console.log("development") 。 如果你遗漏了单引号,它将变成console.log(development) ,由于没有可变development ,这会失败。 This webpack plugin is going to be doing interpol ...
  • 问题 有限自动机 - 正则表达式的理论等价物 - 无法解析递归结构 。 由于您可以使用内部引号和可能的内部引号,因此使用正则表达式无法解决您的问题。 虽然现代的正则表达式引擎可以通过几个扩展来克服这个问题,但不要浪费你的时间在引号内搜索引号。 您很快就会发现,您实际上正在构建一个完整的JSON解析器。 正如@ johnchen902所说 ,即使是图灵机驱动的解析器也无法处理歧义 - 所以你最好不要试图修复破坏的JSON。 解决方案 使用专用实用程序创建JSON 给定的字符串不是有效的JSON 。 它可能是使 ...
  • 这适用于您的示例: Regex.Replace("\"MIKE YANICK\",\"412 A AVE \"E\",\" \",\"NADIEN PA\",\" \",\"190445468\"", "(?<=\")([^,]*)(?=\")", m => m.Value.Replace("\"", string.Empty)) ; 输出: "MIKE YANICK","412 A AVE E"," ","NADIEN PA"," ","190445468" This works wi ...
  • 第一行中的双引号是编译器的语法工件,用于区分字符串文字和变量名称。 它们不在字符串中; 字符串是chestarmor_105 ,没有双引号。 如果你写 pictureBox1.Image = MediaLib.Get[chestarmor_105]; // no quotes 编译器会认为chestarmor_105代表一个标识符; 你将chestarmor_105用双引号括起来告诉编译器你想把它直接用作14个字符的字符串,而不是变量名。 然后编译器删除双引号,并将该值用作字符串。 这应该工作: stri ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)