0

例如,我有这样的数组字符串。下面是 Example[0] 的字符串

Name\r\n
Gamma\r\n
ID\r\n
3F97\r\n
CAR\r\n
Mitsubishi EVO LAN V\r\n

好吧,我想将此字符串中的此值复制到 Example[0]

Name\r\n
Gamma\r\n
ID\r\n
3F97\r\n
CAR\r\n
Mitsubishi EVO LAN V\r\n
Name\r\n
Gamma\r\n
ID\r\n
3F98\r\n
CAR\r\n
Mitsubishi EVO LAN V\r\n

有没有办法做到这一点?请注意,更改是从3F973F98的 ID 下面

4

2 回答 2

1

您可以按行尾拆分字符串,更改第四行,加入它并将其连接到第一个字符串。

于 2012-02-05T07:10:22.110 回答
0

I think your question might be giving the wrong impression, correct me if I'm wrong, but what you have here is a class that defines a 'car'.

Why then don't you just create an actual class to represent a car and implement a ToString() method?

public class Car {

    public string Name {get;set}
    public string ID {get;set;}
    public string CAR {get;set;}

    public Car(string name,string id,string car){
        Name = name;
        ID = id;
        CAR = car;
    }

    public override string ToString(){
        return string.format("Name: {0}, ID: {1}, CAR: {2}",Name,ID,CAR);
    }
}

Then, instead of an array of strings, have an array of cars, which you can duplicate as you please and modify if necessary.

You will also have a central place to modify the format of the output, i.e. the Car class definition (even though in normal circumstances, I would never promote a ToString() method like this for output, other than that directed to a logger)

于 2012-02-06T00:22:58.097 回答