Ket*_*ukh 2 ruby regex arrays ruby-on-rails backslash
我想以下面的方式在ruby中定义一个数组
A = ["\"]
Run Code Online (Sandbox Code Playgroud)
我现在被困在这里好几个小时了.尝试了单引号和双引号的几种可能组合,前向和后向斜杠.唉!!
我也看过这个链接:这里 但是无法理解如何解决我的问题.
除此之外,我需要做的是 - 1.逐个字符地读取文件(我设法做到了!)2.这个文件包含一个"\"字符3.如果我的数组A包含这个反斜杠,我想做点什么
A.includes?("\")
Run Code Online (Sandbox Code Playgroud)
任何帮助赞赏!
有些字符很特殊,需要转义.就像定义字符串一样
str = " this is test string \
and this contains multiline data \
do you understand the backslash meaning here \
it is being used to denote the continuation of line"
Run Code Online (Sandbox Code Playgroud)
在用双引号""定义的字符串中,如果你需要双引号,你会怎么做?"\"",这就是为什么当你在一个字符串中放一个反斜杠时你会告诉解释器你将使用一些特殊字符并用反斜杠转义.所以当你从文件中读取一个"\"时,它将会被读取将"\"改成红宝石串.
char = "\\"
char.length # => 1
Run Code Online (Sandbox Code Playgroud)
我希望这有帮助 ;)