C# 重复字符串,行内略有变化
例如我有这样的数组字符串。下面是示例 [0] 的字符串
Name\r\n
Gamma\r\n
ID\r\n
3F97\r\n
CAR\r\n
Mitsubishi EVO LAN V\r\n
,我想将此字符串中的值复制到示例 [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
无论如何可以做到这一点吗? 请注意,更改位于 ID 下方,从 3F97 更改为 3F98
For example i have strings of array like this. Below is the string of Example[0]
Name\r\n
Gamma\r\n
ID\r\n
3F97\r\n
CAR\r\n
Mitsubishi EVO LAN V\r\n
well i would like to duplicate this value from this string into 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
is there anyway to do this?
note that the change is below the ID from 3F97 into 3F98
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以按行尾拆分字符串,更改第四行,将其连接并将其连接到第一个字符串。
You can split the string by end-of-line, change the fourth line, join it and concatenate it to the first string.
我认为你的问题可能会给人错误的印象,如果我错了请纠正我,但你这里有一个定义“汽车”的类。
那么为什么不创建一个实际的类来表示汽车并实现 ToString() 方法呢?
然后,使用汽车数组代替字符串数组,您可以随意复制该数组,并在必要时进行修改。
您还将有一个修改输出格式的中心位置,即
Car
类定义(即使在正常情况下,我永远不会推广像这样的 ToString() 方法用于输出,除了指向记录器)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?
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)