小编Vim*_*tel的帖子

试图理解带对象的==运算符

object a = "1";
object b = "1";
Console.WriteLine(a == b); // returns True

object c = 1;
object d = 1;
Console.WriteLine(c == d); // returns False
Run Code Online (Sandbox Code Playgroud)

上面的代码返回整数和字符串的不同结果.我无法理解为什么.有人可以帮我理解这背后的原因吗?

==(运营商)和ReferenceEquals(功能)有什么区别?

c#

13
推荐指数
3
解决办法
1468
查看次数

使用正则表达式替换javascript中的情感字符

我有以下JavaScript代码.

var emoticons = {
    ':)': '<span class="emoticon emoticon_smile"></span>',
    ':-)': '<span class="emoticon emoticon_smile"></span>',
    ':(': '<span class="emoticon emoticon_sad"></span>',
    ':d': '<span class="emoticon emoticon_bigSmile"></span>',
    ':D': '<span class="emoticon emoticon_bigSmile"></span>'
}
Run Code Online (Sandbox Code Playgroud)

现在要用给定文本中的span替换情感我正在使用以下函数

function Emotions (text) {
    if (text == null || text == undefined || text == "") return;
    var pattern = /[:\-)(D/pPy@'*]+/gi;
    return text.replace(pattern, function (match) {
        return typeof emoticons[match] != 'undefined' ?
           emoticons[match] :
           match;
    });
}
Run Code Online (Sandbox Code Playgroud)

现在上面的代码工作正常.如果我在函数中传递文本如下

Emotions("Hey this is a test :( :(");
Run Code Online (Sandbox Code Playgroud)

看到两种情绪之间的空间.但如果我删除两种情感之间的空间,那么它就不起作用.如下所示

Emotions("Hey this is a test :(:(");
Run Code Online (Sandbox Code Playgroud)

我的正则表达式有问题,但我无法弄明白.

javascript regex jquery

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

有角材料;mat-select 显示选定的颜色

我有这段代码来显示用户可以选择的颜色列表:

<form>
    <h4>mat-select</h4>
    <mat-form-field appearance="fill">
        <mat-label>Favorite Color</mat-label>
        <mat-select [(ngModel)]="selectedValue" name="food">
            <mat-option *ngFor="let color of allColors" [value]="'#' + color.value">
                <!-- {{color.label}}  -->
                <span class="color-span" [ngStyle]="{ 'background-color': '#' + color.value }"></span>
            </mat-option>
        </mat-select>
    </mat-form-field>

</form>

import {Component} from '@angular/core';
/**
 * @title Select in a form
 */
@Component({
  selector: 'select-form-example',
  templateUrl: 'select-form-example.html',
})
export class SelectFormExample {
  public allColors: any[] = [
  {label: 'FFFFFF', value: 'FFFFFF'},
  {label: '000000', value: '000000'},
  {label: '603813', value: '603813'},
  {label: 'FF0000', value: 'FF0000'},
  {label: '2E3192', value: '2E3192'}, …
Run Code Online (Sandbox Code Playgroud)

html css angular-material angular

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

标签 统计

angular ×1

angular-material ×1

c# ×1

css ×1

html ×1

javascript ×1

jquery ×1

regex ×1