本文介绍了解释一下用JAVA编写的这一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HACKERRANK中,这行代码非常频繁地出现.我认为这是为了跳过空格,但是"\r\u2028\u2029\u0085"的意思是什么

In HACKERRANK this line of code occurs very frequently. I think this is to skip whitespaces but what does that "\r\u2028\u2029\u0085" thing mean

 scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

推荐答案

Scanner.skip跳过与模式匹配的输入,这里的模式是:-

  • ?完全匹配零或前一个字符.
  • |替代
  • []匹配
  • 中出现的单个字符
  • \ r匹配回车符
  • \ n换行符

  • ? matches exactly zero or one of the previous character.
  • | Alternative
  • [] Matches single character present in
  • \r matches a carriage return
  • \n newline

\ u2028将字符与区分大小写的索引2018 base 16(8232 base 10或20050 base 8)匹配

\u2028 matches the character with index 2018 base 16(8232 base 10 or 20050 base 8) case sensitive

  • \ r与回车符(ASCII 13)匹配
  • \ n与换行符(ASCII 10)匹配
    • 匹配[\ n \ r \ u2028 \ u2029 \ u0085]下面列表中存在的单个字符
    • \ n与换行符(ASCII 10)匹配
    • \ r与回车符(ASCII 13)匹配
    • \ u2028从字面上(区分大小写)LINE SEPARATOR匹配具有索引202816(823210或200508)的字符
    • \ u2029从字面上将字符与索引202916(823310或200518)相匹配(区分大小写)PARAGRAPH SEPARATOR
    • \ u0085从字面上(区分大小写)将索引为8516(13310或2058)的字符与下一行匹配
      • Match a single character present in the list below [\n\r\u2028\u2029\u0085]
      • \n matches a line-feed (newline) character (ASCII 10)
      • \r matches a carriage return (ASCII 13)
      • \u2028 matches the character with index 202816 (823210 or 200508) literally (case sensitive) LINE SEPARATOR
      • \u2029 matches the character with index 202916 (823310 or 200518) literally (case sensitive) PARAGRAPH SEPARATOR
      • \u0085 matches the character with index 8516 (13310 or 2058) literally (case sensitive) NEXT LINE
      • 这篇关于解释一下用JAVA编写的这一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 17:00