标签: and-operator

在**if语句中使用**和**运算符**

我被一位朋友带到了这个网站.

我试图and在Delphi中使用,但我似乎做错了.你需要投入使用吗?

我有以下代码:

procedure TForm1.Button1Click(Sender: TObject);
var
a,b:string;
begin
a:=edit1.Text;
b:=edit2.Text;

if a=abc and b=def then
showmessage(a+b);

end;
Run Code Online (Sandbox Code Playgroud)

我在第二个=符号时收到错误

delphi if-statement and-operator

6
推荐指数
3
解决办法
3万
查看次数

通过PHP中的AND运算符进行短路评估

我正在努力提高我的编码忍者h4x技能,我目前正在寻找不同的框架,我找到了很难谷歌的示例代码.

我正在研究项目中使用的FUEL框架.

我不明白的样本是

$data and $this->template->set_global($data);
Run Code Online (Sandbox Code Playgroud)

什么是关键字这行代码在做什么?它被用在框架中的许多地方,它是我发现的第一个使用它的地方.

php and-operator

6
推荐指数
1
解决办法
502
查看次数

重新定义__and__运算符

为什么我不能重新定义__and__运算符?

class Cut(object):
      def __init__(self, cut):
         self.cut = cut
      def __and__(self, other):
         return Cut("(" + self.cut + ") && (" + other.cut + ")")

a = Cut("a>0") 
b = Cut("b>0")
c = a and b
print c.cut()
Run Code Online (Sandbox Code Playgroud)

我想(a>0) && (b>0),但我得到了b,通常的行为and

python operators redefine and-operator

5
推荐指数
1
解决办法
1993
查看次数

在Angular ng-if表达式中使用&(按位AND运算符)

我无法使&操作符在Angular ng-if表达式中工作(与一些位标志一起使用).假设我们有这样的HTML:

<div ng-if="value & 2"> </div>
Run Code Online (Sandbox Code Playgroud)

如果value等于3,则按位运算应返回2,因此返回真值.

但是,Angular Syntax Error每次都会抛出一个异常.操作不被允许吗?或者我做错了什么?

链接到plunker.

编辑:我已经通过使用一个简单的函数解决了我的问题:

$scope.checkFlag = function(value, flag){
   return value & flag;
}
Run Code Online (Sandbox Code Playgroud)

但我真的不喜欢这个解决方案.有没有办法在它中使用它ng-if(显然不使用该功能)?

javascript syntax bitwise-operators and-operator angularjs

5
推荐指数
1
解决办法
8749
查看次数

带有负参数的正则表达式 AND 运算符

我想匹配,不与任何一端线.!并且不与任何一端."!"因此它应该同时匹配

  • say "bye"
  • say "bye

但不应该匹配:

  • say "bye.
  • say "bye!
  • say "bye."
  • say "bye!"

我尝试使用正面和负面的前瞻,尝试将它们用作正则表达式 AND 运算符中建议的AND,但我无法使其工作,我也不确定使用前瞻是可行的。

regex jedit and-operator

5
推荐指数
1
解决办法
334
查看次数

如何在特定持续时间之间在php中显示任何内容?

我有一个如下所示的php代码,我想在一周的两个日历日之间显示任何内容。

的值来内$data->{"select_start_day"}; $data->{"start_time"}; $data->{"select_end_day"};并且$data->{"end_time"};由用户控制的。

PHP代码:

    if (file_exists('feeds/ptp-ess_landing.json')) {
    $data = json_decode(file_get_contents('feeds/ptp-ess_landing.json'));
    }

    date_default_timezone_set('America/Toronto');
    $arradate = strtolower(date('D'));
    $nowtime = (int)date('His');


    $start_day=$data->{"select_start_day"};
    $start_time=$data->{"start_time"};

    $end_day=$data->{"select_end_day"};
    $end_time=$data->{"end_time"};
Run Code Online (Sandbox Code Playgroud)

例如,让我们假设用户输入$start_daysun $start_time143400 $end_day作为wed $end_time作为140000

以上持续时间表示我们处于范围内,并且应该显示我们要显示的任何内容,直到明天下午2点为止。我在美国东部时间。

我正在使用以下代码以获取星期几和时间的当前日期

date_default_timezone_set('America/Toronto');
$arradate = strtolower(date('D'));
$nowtime = (int)date('His');
Run Code Online (Sandbox Code Playgroud)

问题陈述:

我想知道如果我需要使用逻辑,以便它打印任何内容Sunday 143400Wednesday 140000

if()    {
    echo "Its in range";
}
Run Code Online (Sandbox Code Playgroud)

情况:

  1. 如果该替代适用于从上午8点星期一到下午6 星期一,而今天是星期三,则该替代不适用。

  2. 如果它是星期一下午6点和 …

php time if-statement date and-operator

5
推荐指数
1
解决办法
328
查看次数

PHP 中 VB 的“AndAlso”等价物是什么?

*此外,And操作符是否已经像 一样AndAlso,或者两者都以不同的方式存在?

php vb.net operators logical-operators and-operator

4
推荐指数
1
解决办法
2747
查看次数

C关系运算符输出

#include <stdio.h>
void main()
{
    int x = 1, y = 0, z = 5;
    int a = x && y || z++;
    printf("%d", z);
}
Run Code Online (Sandbox Code Playgroud)

这产生了6的输出

#include <stdio.h>
void main()
{
    int x = 1, y = 0, z = 5;
    int a = x && y && z++;
    printf("%d", z);
}
Run Code Online (Sandbox Code Playgroud)

这会产生答案为5.为什么?有人请解释一下.

c logical-operators or-operator and-operator

4
推荐指数
2
解决办法
3032
查看次数

R - 查找包含所有字符串/模式的所有向量元素 - str_detect grep

样本数据

files.in.path = c("a.4.0. name 2015 - NY.RDS", 
                  "b.4.0. name 2016 - CA.RDS", 
                  "c.4.0. name 2015 - PA.RDS")
strings.to.find = c("4.0", "PA")
Run Code Online (Sandbox Code Playgroud)

我想要显示包含所有元素的逻辑向量strings.to.find。结果想要:

FALSE FALSE TRUE
Run Code Online (Sandbox Code Playgroud)

此代码将查找包含以下任何一项的元素strings.to.find,即,使用 OR 运算符

str_detect(files.in.path, str_c(strings.to.find, collapse="|")) # OR operator
 TRUE TRUE TRUE
Run Code Online (Sandbox Code Playgroud)

此代码尝试使用 AND 运算符但不起作用。

str_detect(files.in.path, str_c(strings.to.find, collapse="&")) # AND operator
FALSE FALSE FALSE
Run Code Online (Sandbox Code Playgroud)

这在几行中有效,我可以编写一个for循环,该循环将为具有大量strings.to.find

det.1 = str_detect(files.in.path,      "4.0"  )   
det.2 = str_detect(files.in.path,      "PA"  )   
det.all = det.1 & det.2
 FALSE FALSE  TRUE
Run Code Online (Sandbox Code Playgroud)

但是有没有更好的方法不涉及使用依赖于strings.to.find.

r and-operator stringr grepl

4
推荐指数
2
解决办法
5716
查看次数

constexpr 上下文中运算符 &amp;&amp; 的奇怪行为

以下代码尝试根据参数包中传递的最后一个参数做出编译时决策。如果参数包参数的数量 > 0,它包含一个比较,然后尝试获取它的最后一个元素。但是,构造的元组是在无效索引处访问的,该索引据称大于最大元组索引(如图所示static_assert)。
如果我这样做怎么可能cnt-1

演示

#include <cstdio>
#include <concepts>
#include <utility>
#include <tuple>


template <typename... Args>
auto foo(Args&&... args)
{
    auto tuple = std::forward_as_tuple(std::forward<Args>(args)...);
    constexpr std::size_t cnt = sizeof...(Args);

    if constexpr (cnt > 0 && std::same_as<std::remove_cvref_t<std::tuple_element_t<cnt-1, decltype(tuple)>>, int>) {
        printf("last is int\n");
    } else {
        printf("last is not int\n");
    }
}

int main()
{
    foo(2);

    foo();
}
Run Code Online (Sandbox Code Playgroud)

错误:

/opt/compiler-explorer/gcc-12.2.0/include/c++/12.2.0/tuple: In instantiation of 'struct std::tuple_element<18446744073709551615, std::tuple<> >':
<source>:13:25:   required from 'auto foo(Args&& ...) [with Args = {}]' …
Run Code Online (Sandbox Code Playgroud)

c++ tuples and-operator if-constexpr

4
推荐指数
1
解决办法
133
查看次数