小编Fid*_*eak的帖子

将字符串值"$ false"转换为布尔变量

我这样做的原因

我正在尝试在我拥有的文件中设置令牌.令牌的内容在文件中是1行,它的字符串值是$token=$false

简化为测试代码

当我尝试将此令牌转换为bool值时,我遇到了一些问题.所以我写了测试代码,发现我无法将字符串转换为bool值.

[String]$strValue = "$false"
[Bool]$boolValue = $strValue

Write-Host '$boolValue =' $boolValue
Run Code Online (Sandbox Code Playgroud)

这给出了以下错误......

Cannot convert value "System.String" to type "System.Boolean", parameters of this type only accept booleans or numbers, use $true, $false, 1 or 0 instead.
At :line:2 char:17
+   [Bool]$boolValue <<<<  = $strValue
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我正在使用$false错误消息建议的值,但它不接受它.有任何想法吗?

powershell powershell-3.0

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

将日期格式从"yyyymmdd"更改为"mm/dd/yyyy"

我尝试了很多不同的方法,但我似乎无法做到这一点.

这是我到目前为止所尝试的代码......

[String]$dateValue = '20161212'
[String]$dateStamp = $dateValue -f (Get-Date)
[String]$dateStamp2 = ([datetime]::parseexact($dateValue, "yyyyMMdd", [System.Globalization.CultureInfo]::InvariantCulture)).Date
[String]$dateStamp3 = ([datetime]::FromFileTime($dateValue)).ToString('g')

Write-Host '$dateStamp  = ' $dateStamp
Write-Host '$dateStamp2 = ' $dateStamp2
Write-Host '$dateStamp3 = ' $dateStamp3
Run Code Online (Sandbox Code Playgroud)

当前代码输出

$dateStamp = 20161212
$dateStamp2 = 12/12/2016 00:00:00
$dateStamp3 = 12/31/1600 5:00 PM
Run Code Online (Sandbox Code Playgroud)

期望的代码输出

$dateStamp = 12/12/2016
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

powershell powershell-3.0

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

仅在嵌套循环中突破内循环

我正在尝试实现一个中断,所以当我得到结果xxxxx次时我不必继续循环.

$baseFileCsvContents | ForEach-Object {
    # Do stuff
    $fileToBeMergedCsvContents | ForEach-Object {
        If ($_.SamAccountName -eq $baseSameAccountName) {
            # Do something
            break
        }
        # Stop doing stuff in this For Loop
    }
    # Continue doing stuff in this For Loop
}
Run Code Online (Sandbox Code Playgroud)

问题是,break正在退出两个ForEach-Object循环,我只想让它退出内循环.我尝试过读取和设置标志:outer,但是我得到的只是语法错误.

有人知道怎么做吗?

powershell powershell-3.0

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

将二维 ArrayList 复制为新的

所以我遇到的问题是复制二维数组列表后,从一个二维数组列表更改元素会影响另一个二维数组列表。我希望它们在内存中完全分开。

第一个示例显示了它如何与一维数组列表一起正常工作...

import java.util.ArrayList;
public class QuickTest {

    public static void main(String[] args) {
        ArrayList<Integer> firstList = new ArrayList<>();
        ArrayList<Integer> secondList = new ArrayList<>();

        Integer counter = 2;
        for(int arrI = 0; arrI < 4; arrI++, counter+=2){
            firstList.add(counter);
        }

        secondList = new ArrayList<>(firstList);

        System.out.println("firstList.get(2) = " + firstList.get(2));
        System.out.println("secondList.get(2) = " + secondList.get(2));

        firstList.set(2, 7);

        System.out.println("firstList.get(2) = " + firstList.get(2));
        System.out.println("secondList.get(2) = " + secondList.get(2));
    }
}
Run Code Online (Sandbox Code Playgroud)

预期输出:

在此处输入图片说明

请注意第一个 arraylist 中的元素如何更改,但第二个 arraylist 元素未更改。这很好,也是我们想要的。

现在尝试复制二维数组列表...

import java.util.ArrayList;
public class QuickTest { …
Run Code Online (Sandbox Code Playgroud)

java arraylist

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

ASP.NET Core 3.1“‘用户’不包含‘FindFirstValue’的定义”

在尝试从此处实现答案时>如何在 ASP.NET Core 中获取当前登录的用户 Id 以及用户将我重定向到此处> https://github.com/dotnet/aspnetcore/issues/18348

var UserId = User.FindFirstValue(ClaimTypes.Name);

^ 这不起作用,并打印以下错误'User' does not contain a definition for 'FindFirstValue'

编辑:添加控制器片段

我的控制器的完整片段...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using ProjectName.Processing;
using ProjectName.Repository;
using Newtonsoft.Json;

namespace ProjectName.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class ClassNameController : ControllerBase
    {
        private readonly ILogger<ClassNameController> _logger;
        private OtherClassNameProcessing proc = new OtherClassNameProcessing();

        public ClassNameController(ILogger<ClassNameController> logger)
        {
            _logger = logger;
        }

        [HttpGet]
        [ProducesResponseType(typeof(List<2ndOtherClassNameRepository>), StatusCodes.Status200OK)]
        public IActionResult GetUserName()
        { …
Run Code Online (Sandbox Code Playgroud)

.net-core asp.net-core asp.net-core-identity .net-core-3.1

3
推荐指数
2
解决办法
7177
查看次数

仅从int值中删除csv文件中的前导零

我有这个csv文件我正在尝试删除前导零,但是我的代码中包含任何带有字母或特殊字符的数字,它会使值无效,我不希望...

column1                        ,column2                            ,column3   ,column4       ,column5,column6,column7,column8 ,column9,column10,column11,column12,column13 ,column14,column15,column16
0000013                        ,                                   ,ShopKeep  ,Store         ,       ,       ,       ,        ,       ,1034627 ,        ,        ,         ,        ,        ,
0000032                        ,                                   ,Test411   ,User411       ,0007643,       ,       ,        ,       ,1034632 ,        ,        ,         ,        ,        ,
0000142                        ,                                   ,Pinky     ,Brain         ,0571253,       ,       ,        ,J      ,1234    ,        ,        ,         ,        ,        ,
0000145                        ,Leo@ninjaturtles.com               ,Leo       ,Turtle        ,0661203,       ,       ,        ,J      ,2345    ,        ,        ,RNixon   ,        ,        ,
0000264                        ,                                   ,Richard   ,Nixon         ,0311247,       ,       ,        ,J      ,3456    ,        , …
Run Code Online (Sandbox Code Playgroud)

powershell powershell-3.0

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

仅从 csv 文件中删除重复记录

我试过谷歌搜索不同的东西,但我似乎无法找到答案。

CSV 内容

"ColumnOne","ColumnTwo","ColumnThree"
"C1V1","C2V1","C3V1"
"C1V2","C2V2","C3V2"
"C1V2","C2V2","C3V2"
"C1V3","C2V3","C3V3"
Run Code Online (Sandbox Code Playgroud)

代码

$input = 'C:\Temp\test.csv'
$inputCsv = Import-Csv $input | Select-Object -Unique

$inputCsv | Export-Csv "$input-temp.csv" -NoTypeInformation
#Move-Item "$input-temp.csv" $input -Force
Run Code Online (Sandbox Code Playgroud)

输出

"ColumnOne","ColumnTwo","ColumnThree"
"C1V2","C2V2","C3V2"
Run Code Online (Sandbox Code Playgroud)

预期输出

"ColumnOne","ColumnTwo","ColumnThree"
"C1V1","C2V1","C3V1"
"C1V2","C2V2","C3V2"
"C1V3","C2V3","C3V3"
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一点?

powershell powershell-3.0

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

设置 JSperator 的宽度

我想弄清楚如何增加 JSeparator 的线条粗细。我尝试的一切似乎都不起作用,我似乎无法在 API 中找到解决方案。

这是代码...

import org.apache.commons.lang3.ArrayUtils;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;

public class TestGui extends JFrame {
    private final String[] guiCharSelDefault = {"---  Select Character ---"};
    private final String[] characters = {"charOne", "charTwo", "charThree", "charFour"};
    private final String[] GuiCharSel = (String[]) ArrayUtils.addAll(guiCharSelDefault, characters);
    private final String[] weapon = {"Weapon"};
    private final String[][] allWeapons = {
            {
                    "weakWeaponOne", "strongWeaponOne", "shortWeaponOne", "longWeaponOne"
            },
            {
                    "weakWeaponTwo", "strongWeaponTwo", "shortWeaponTwo", "longWeaponTwo"
            },
            {
                    "weakWeaponThree", "strongWeaponThree", "shortWeaponThree", …
Run Code Online (Sandbox Code Playgroud)

java swing

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

reportWebVitals 缺少返回类型

开箱即npx create-react-app app-name --template typescript用的结果如下:

在此输入图像描述

我似乎找不到任何关于此预期返回类型的信息。有人有主意吗?

typescript reactjs

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

jwt-decode“该表达式不可调用。” 带打字稿

刚开始看到这个错误。

我知道这与这里的问题有关:Using jwt-decode with typescript front-end project

然而,我已经在尝试答案,但它不起作用......

在此输入图像描述

代码

import jwt from 'jwt-decode';

export function isTokenExpired(token: string): boolean {
  // check token payload
  const tokenPayload: any = jwt(token);
  // check token expiration date in payload
  const tokenExpiration = tokenPayload.exp;
  const now = Math.floor(new Date().getTime() / 1000); // token exp shaved off milliseconds
  // if (expiration date is greater than current date)
  return now > tokenExpiration;
}
Run Code Online (Sandbox Code Playgroud)

错误

This expression is not callable.
  Type 'typeof import("c:/Projects/msal-react-native-expo/node_modules/jwt-decode/build/cjs/index")' has no call signatures.ts(2349)` …
Run Code Online (Sandbox Code Playgroud)

jwt typescript react-native expo

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