C# third index of a character in a string

前端 未结 10 1971
甜味超标
甜味超标 2020-12-06 17:18

is there a command that can get the third index of a character in a string? For example:

error: file.ext: line 10: invalid command [test:)]

10条回答
  •  难免孤独
    2020-12-06 17:58

    Simply split the string by the char. This gives you an array that you can then use to target what you want.

    var stringToSplit = "one_two_three_four";
    var splitString = stringToSplit.Split("_");          
    if (splitString.length > 3){
        var newString = $"{splitResult[0]}_{splitResult[1]}_{splitResult[2]}";
    }
    

提交回复
热议问题