从arry中删除字符串的第一个逗号

时间:2020-06-22 12:12:26

标签: javascript angular

在此先感谢您的答复,我正在检查ddbb来带上某些物品的名称,并将其画在我的ts中,如下:

app-batch-app-management.ts

Map<String, int> dirStatSync(String dirPath) {
  int fileNum = 0;
  int totalSize = 0;
  var dir = Directory(dirPath);
  try {
    if (dir.existsSync()) {
      dir.listSync(recursive: true, followLinks: false)
        .forEach((FileSystemEntity entity) {
          if (entity is File) {
            fileNum++;
            totalSize += entity.lengthSync();
          }
        });
    }
  } catch (e) {
    print(e.toString());
  }

  return {'fileNum': fileNum, 'size': totalSize};
}

和我的app-batch-app-management.html


import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-batch-app-management',
  templateUrl: './batch-app-management.component.html',
  styleUrls: ['./batch-app-management.component.scss']
})

  constructor(private location: Location,
    private activatedRoute: ActivatedRoute,
    private deviceService: DeviceService,
    private appManagementService: AppManagementService) {
    this.deviceNameList = "";
    this.mgmtErrorMessage = null;
    this.deviceId = "";


    this.mgmtErrorMessage = null;

  }

  ngOnInit() {
    this.activatedRoute.queryParams.subscribe(params => {
      this.mgmtErrorMessage = null;
      this.deviceIdList = params["deviceList"];
      this.deviceId = this.deviceIdList[0];


    });
    for (let i = 0; i < this.deviceIdList.length; i++) {
      this.deviceService.getDeviceName(this.deviceIdList[i]).then(deviceName => {
        // if (i === 0) {
        //   this.deviceNameList = deviceName;
        // } else {
        this.deviceNameList += ", " + deviceName;
        // }

      }).catch(err => {
        this.mgmtErrorMessage = "Oops, could not get the device configuration.";
      });
    }
  }

我的ts中的上述条件并不总是绘制所有项目,我认为由于该条件,所以我想删除它,但是它首先绘制了逗号,我如何删除第一个逗号?

3 个答案:

答案 0 :(得分:0)

您可以只使用substring方法:

this.deviceNameList = this.deviceNameList.substring(2);

答案 1 :(得分:0)

使用基本正则表达式,您可以在字符串中用逗号替换逗号:

“,your,String” .replace(/ ^,/,'')

注意::正则表达式中的^将删除第一个字符

答案 2 :(得分:0)

请勿在循环内使用library(tidyverse) data %>% group_by(Group) %>% arrange(Date) %>% mutate(New = as.numeric(Date - Date[which.max(G)])) ,这会导致不良后果(这就是您的条件检查失败的原因,因为它引用了关闭变量)。而是Promise.then,这样您的支票就可以使用,或者用await解决逗号问题:

join()