C# third index of a character in a string

前端 未结 10 1957
甜味超标
甜味超标 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 18:06

    I am guessing you want to parse that string into different parts.

    public static void Main() {
        var input = @"error: file.ext: line 10: invalid command [test (: ]";
        var splitted = input .Split(separator: new[] {": "}, count: 4, options: StringSplitOptions.None);
    
        var severity = splitted[0]; // "error"
        var filename = splitted[1]; // "file.ext"
        var line = splitted[2];     // "line 10"
        var message = splitted[3];  // "invalid command [test (: ]"
    }
    

提交回复
热议问题