新手问题 求帮忙看看这句代码的逻辑是什么?

string2020 · January 09, 2015 · Last by Rei replied at January 10, 2015 · 1870 hits
if c_number.to_s.include?('十')
      index = (c_number =~ /十/)
      c_number = c_number.gsub('十', '') if !c_number[index-1].to_i==0 and !c_number[index+1].to_i==0
      c_number = c_number.gsub('十', '1') if !c_number[index+1].to_i==0
      c_number = c_number.gsub('十', '0') if !c_number[index-1].to_i==0
      c_number = c_number.gsub('十', '10')
end

实在是看不懂,求帮忙

这代码本身有问题,/十/这就有问题。。。。

#1 楼 @wpzero 先不管有没有问题,我只想知道作者想要干什么 然后,我用C#实现同样的功能

代码结构看懂了,但没有上下文不知道他想干什么

#3 楼 @bo6bear c_number = c_number.gsub('十', '') if !c_number[index-1].to_i==0 and !c_number[index+1].to_i==0 c_number = c_number.gsub('十', '1') if !c_number[index+1].to_i==0 c_number = c_number.gsub('十', '0') if !c_number[index-1].to_i==0

这三句 干啥的

替换的逻辑是什么

如果十前后都不是 0,就把十干掉; 如果后面是 0,就换成 1 如果前面是 0,就换成 0

给原作者发邮件啊。

You need to Sign in before reply, if you don't have an account, please Sign up first.