我刚开始使用GO,我理解SCANF在GO中使用空格作为分隔符.
fmt.Scanf("%s",&input)
Run Code Online (Sandbox Code Playgroud)
我真的找不到一种方法来接受包含空格作为有效字符的输入.
我有以下代码来检查在Ada中输入的字符串是否是字母数字:
function Check_AplhaNumeric(input_String:in String) return Boolean is
begin
Alphanumeric_or_not:=TRUE;
for Index_Character in 1..Length(To_Unbounded_String(input_String)) loop
Alphanumeric_or_not:=Is_Alphanumeric(Character'Val(Character'Pos(input_String(Index_Character))));
exit when Alphanumeric_or_not = False;
end loop;
return True;
end Check_AplhaNumeric;
Run Code Online (Sandbox Code Playgroud)
下面的代码调用上面的函数三次
Is_it:=Check_AplhaNumeric(stringInput(1..First_Semicolon-1));
Is_it:=Check_AplhaNumeric(stringInput(First_Semicolon+1..Second_Semicolon-1));
Is_it:=Check_AplhaNumeric(stringInput(Second_Semicolon+1..stringInput'Last));
Run Code Online (Sandbox Code Playgroud)
我有一个输入字符串,例如:a;value;b根据输入中的分号分为三个部分.第一个调用Check_AlphaNumeric工作正常并检测字符串是否为字母数字,但是,包含字符串中第二和第三部分的调用会产生以下错误:
raised CONSTRAINT_ERROR : alpha.adb:247 index check failed
Run Code Online (Sandbox Code Playgroud)
我不知道出现了什么问题,因为当我第一次在字符串中的第一个分号之前调用它时它工作得很好.
即使其中一个字符不是字母数字,我也需要它来打印一些消息并退出程序.