我有多个switch语句,但在某些情况下我需要常见的情况.所以,我正在尝试
OR operator => ||
例:
<ng-container [ngSwitch]="options">
<ng-container *ngSwitchCase="'a'">Code A</ng-container>
<ng-container *ngSwitchCase="'b'">Code B</ng-container>
<ng-container *ngSwitchCase="'c'">Code C</ng-container>
<ng-container *ngSwitchCase="'d' || 'e' || 'f'">Common Code</ng-container>
<ng-container *ngSwitchDefault>Code Default</ng-container>
</ng-container>
Run Code Online (Sandbox Code Playgroud)
输出:
if case = 'd' returns Common Code
else if case = 'e' and 'f' returns the Code Default
Run Code Online (Sandbox Code Playgroud)
这里的第二个案例由多个案例组成,现在默认情况下case 'd'只有工作且不起作用case 'e' and 'f'.
我在ngSwitchCase文档中看不到任何多个案例:
https://angular.io/docs/ts/latest/api/common/index/NgSwitchCase-directive.html https://angular.io/docs/ts/latest/api/common/index/NgSwitch-directive.html
Angular 2不支持||运营商ngSwitchCase吗?
这很好:
def foo
a or b
end
Run Code Online (Sandbox Code Playgroud)
这也没关系:
def foo
return a || b
end
Run Code Online (Sandbox Code Playgroud)
返回void value expression:
def foo
return a or b
end
Run Code Online (Sandbox Code Playgroud)
为什么?它甚至没有被执行; 它没有通过语法检查.什么void value expression意思?
我有我的正则表达式/'(.*)(?:(?:'\s*,\s*)|(?:'\)))/
和我的测试代码('He said, "You're cool."' , 'Rawr')
(我的测试代码模拟传递给函数的参数.)
我将解释我的正则表达式,因为我理解它,并希望你们中的一些人可以解释我的问题.
1)/'意味着在匹配字符串的开头,需要有'
2)(.*)意味着捕获任何字符,除了\n0次或更多次
3)(?:(?:4)|(?:5))意味着不捕获但尝试执行步骤4,如果它不起作用,请尝试步骤5
4 )(?:'\s*,\s*)意味着不捕获,但需要有一个'0或更多的空白字符后跟一个,0或更多的空格字符
5)(?:'\))意味着不捕获但需要有')
所以它似乎应该返回这个(和是我想要的):
'+ He said, "You're cool."+ ' ,
但它返回:
'+ He said, "You're cool."' , 'Rawr+ ')
如果我将我的测试代码改为('He said, "You're cool."' , 'Rawr'(没有结束括号)它返回我想要的东西,但是一旦我添加了最后一个括号,那么我的OR运算符似乎是不管它想要什么.我希望它首先测试是否有逗号,如果有一个逗号则在那里打破,如果没有一个括号检查.
我已经尝试切换步骤4和步骤5的点,但是OR运算符似乎总是默认为(?:'\))侧面.
我怎样才能匹配尽可能短的数量?
对于我的第一个Java项目,我正在尝试制作一个简单的基于文本的游戏.似乎管道或管道不起作用,当我尝试在它不起作用之后输入内容时; 我必须重启它.
public void GameStart() {
String playerName = "Player";
String Command = "Choice";
System.out.println("Type Start to start game!");
if(in.nextLine().equals("Start") || in.nextLine().equals("start")) {
Help();
print("Type Begin to start game :D");
if(in.nextLine().equals("Begin") || in.nextLine().equals("begin")) {
System.out.println("Who are you?");
Run Code Online (Sandbox Code Playgroud)
开始和开始工作,但第一个字母小写像我使用|| 因为没有.当我使用那些我必须重新启动它因为我不能输入任何东西,但我显然有或管道说要使用任何一个.有谁知道是什么原因引起的?
我在一本书中找到了这个例子:
// Create _callbacks object, unless it already exists
var calls = this._callbacks || (this._callbacks = {});
Run Code Online (Sandbox Code Playgroud)
我简化了它,以便我不必使用特殊的对象范围:
var a = b || (b = "Hello!");
Run Code Online (Sandbox Code Playgroud)
当定义b时,它可以工作.如果未定义b,则它不起作用并抛出ReferenceError.
ReferenceError: b is not defined
Run Code Online (Sandbox Code Playgroud)
我做错了什么吗?谢谢!
我是C的新手,需要帮助.我的代码如下.
#include<stdio.h>
#include<conio.h>
void main()
{
int suite=2;
switch(suite)
{
case 1||2:
printf("hi");
case 3:
printf("byee");
default:
printf("hello");
}
printf("I thought somebody");
getche();
}
Run Code Online (Sandbox Code Playgroud)
我在Turbo C工作,输出是helloI thought somebody.没有错误消息.
请让我知道这是如何工作的.
我只是尝试运行一些看起来像这样的代码
def get_proj4(srid, type=nil)
type.downcase! if type
case type
when nil || "epsg"
open("http://spatialreference.org/ref/epsg/#{srid}/proj4/").read
when "esri"
open("http://spatialreference.org/ref/esri/#{srid}/proj4/").read
end
end
Run Code Online (Sandbox Code Playgroud)
而且它运行不正常,每次都返回nil。将 括nil || "epsg"在括号中也不起作用
事实证明 ruby 不允许我||在此使用运算符
现在我假设 ruby 采用 case/when 方法并最终将其分解为一组看起来像这样的条件
x = type
if x == (nil || "epsg")
y = ...runs code...
elsif x == "esri"
y = ...
end
x = nil
y
Run Code Online (Sandbox Code Playgroud)
但显然事实并非如此。这里发生了什么?
谢谢
如何简化以下检查?...
if node[:base][:database][:adapter].empty? || node[:base][:database][:host].empty? ||
node[:base][:database][:database].empty? || node[:base][:database][:port].empty?
Run Code Online (Sandbox Code Playgroud)
喜欢的东西
required_keys = { :adapter, :host, :database...etc...}
required keys - node[:base][:database] == []
Run Code Online (Sandbox Code Playgroud)
这种语法有点偏,但基本上从所需的密钥集中减去了你的密钥.如果您的集合中包含所有必需的键,则结果应为空.
我不确定正确的语法?.任何帮助,将不胜感激
我不断失去关于如何重新定义|| (“或”)或&&(“和”)二元运算符的参考。我在某处读到,必须首先做的事情importall Base。然后我尝试了
Base.||( x::MyType, y::MyType ) = dosomething( x, y )
Run Code Online (Sandbox Code Playgroud)
并且
Base.or( x::MyType, y::MyType ) = dosomething( x, y )
Run Code Online (Sandbox Code Playgroud)
但这些都不起作用。如果有人可以提供参考解释如何执行此操作的基础知识,我将不胜感激...我无法找到诸如“在 Julia 中重新定义二元运算符”之类的查询...
overloading operator-overloading binary-operators or-operator julia