如何检查char是否符合charset?

如何解决如何检查char是否符合charset?

tl; dr无法解析为使用单个字母

我目前正在学习Red,所以我可能缺少基本的知识,但总的来说,我想检查密码是否包含大写字符;这是我的第一次尝试(我知道这在逻辑上是无效的):

num-uppercase: (length? (difference/case password (lowercase password))) / 2

这个想法是将其转换为小写字符串,然后进行比较,但是difference似乎将字符串转换为set(?)。

现在我从那开始,像这样遍历每个字母:

is-uppercase: false
foreach letter password [
    if letter <> lowercase letter [
        is-uppercase: true
        break
    ]
]

但是后来我想检查单个char! letter是否是特殊字符:

foreach letter password [
    if parse letter special [
        is-special: true
    ]
]

但是我得到一个错误:

*** Script Error: parse does not allow char! for its input argument
*** Where: parse
*** Stack:  

我一直在寻找一种能够检查char是否符合charset的方法,但是不能。

解决方法

Parse几乎适用于任何类型的系列:也就是说,具有一系列连续放置的项目。 char!就是这样的系列,但是>> series? #"." == false >> scalar? #"." == true 却不是。

bitset!

要检查密码是否包含大写字符,首先需要创建一个代表此类字符的>> upper: charset [#"A" - #"Z"] == make bitset! #{00000000000000007FFFFFE0}

>> parse "YES" [some upper]
== true
>> parse "no" [some upper]
== false

在那之后,您可以用它来构造一个解析规则并检查输入的一致性;例如,密码是否全部大写?有些输入会匹配,有些则不会。

>> parse "Sentence" [upper to end]
== true
>> parse "Sentence" [upper any [not upper skip]]
== true

是用句子写的吗?您将要想到的不同语法可以产生相同的结果。

>> parse "aBc" [to upper to end]
== true
>> parse "abc" [to upper to end]
== false

最后,如果要检查是否至少有一个大写字母,应该执行以下操作:

>> parse "aBc" [thru upper any [not upper skip]]
== true
>> parse "aBC" [thru upper any [not upper skip]]
== false

如果您要查找的密码只有一个大写字母,没有更多,那么:

charset!

要直接回答原始问题:如果您有char!>> pick upper #"a" == false >> pick upper #"A" == true >> pick upper [#"A" #"b"] == false >> pick upper [#"A" #"B"] == true >> pick upper "Ab" == false >> pick upper "AB" == true ,则可以使用以下命令检查后者是否属于前者:

node:events:304
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::3000
    at Server.setupListenHandle [as _listen2] (node:net:1286:16)
    at listenInCluster (node:net:1334:12)
    at Server.listen (node:net:1420:7)
    at Function.listen (/home/abubakar/Desktop/Node/express/node_modules/express/lib/application.js:618:24)
    at Object.<anonymous> (/home/abubakar/Desktop/Node/express/my_app.js:24:5)
    at Module._compile (node:internal/modules/cjs/loader:1083:30)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:10)
    at Module.load (node:internal/modules/cjs/loader:948:32)
    at Function.Module._load (node:internal/modules/cjs/loader:789:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:72:12)
Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1313:8)
    at processTicksAndRejections (node:internal/process/task_queues:80:21) {
  code: 'EADDRINUSE',errno: -98,syscall: 'listen',address: '::',port: 3000
}
[nodemon] app crashed - waiting for file changes before starting...

我强烈建议您在处理Parse(FYI拥有官方documentation)之前,先将Red带上轴承。最好的方法是加入Gitter chat,以迅速获得有关您的问题和代码的帮助,并研究社区提供的learning resourcesRebol/Core User Guide是一个很好的起点。

,

红色中的另一种解决方案是将char!转换为integer!并使用path notation

>> special: charset ".:?"
== make bitset! #{0000000000020021}
>> special/(to integer! #"a")
== false
>> special/(to integer! #".")
== true
,

我可以使用to-string将char转换为字符串。这是一种方法。

parse to-string #"." [special]
,

没有解析,但是根据您想要第一次尝试得到的结果

>> strict-equal? lowercase copy pass: "ABcc"  pass
== false
>> strict-equal? lowercase copy pass: "abcc"  pass
== true

您需要 copy ,因为它会更改原始的 strict-equal?,因为普通的 equal?不能区分大写和小写。

差异显示两组的不同项。请参见帮助差异。 您可以从中获得与众不同的解决方案

>> same: empty? difference/case pass: "ABcc" lowercase copy pass
== false
>> same:  empty? difference/case pass: "aabc" lowercase copy pass
== true
,

对于单个字符,static void Main(string[] args) { var userValues = new List<UserValue> { new UserValue { FieldId = 1,FieldValue = "2"},new UserValue { FieldId = 2,FieldValue = "3"},new UserValue { FieldId = 4,FieldValue = "5"} }; var lookupMetas = new List<LookupMeta> { new LookupMeta { FieldId = 1,Id = 2,FieldValueId = 20 },new LookupMeta { FieldId = 2,Id = 3,FieldValueId = 30 },new LookupMeta { FieldId = 3,Id = 4,FieldValueId = 40 },}; var comparer = new IntermediateKeyComparer(); var result = userValues .GroupJoin( lookupMetas,uv => new IntermediateKey { Id = uv.FieldId,Value = uv.FieldValue },lm => new IntermediateKey { Id = lm.FieldId,Value = lm.Id.ToString() },(uv,lm) => new { Value = uv,Lookups = lm},comparer) .SelectMany( pair => pair.Lookups.DefaultIfEmpty(),(x,meta) => new { Value = x.Value,Lookup = meta}) .Select(res => { res.Value.FieldValue = res.Lookup?.FieldValueId.ToString() ?? res.Value.FieldValue; return res.Value; }); foreach (var maybeUpdatedUserValue in result) { Console.WriteLine($"{maybeUpdatedUserValue.FieldId}: {maybeUpdatedUserValue.FieldValue}"); } } 也可以与字符集一起使用。

1: 20
2: 30
4: 5

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res