gpt4 book ai didi

c# - C#-拆分字符串问题

转载 作者:太空宇宙 更新时间:2023-11-03 18:00:56 25 4
gpt4 key购买 nike

我有一组基于分割字符串的值

string[] seperator = new string[9];
seperator[0] = "*"; //is the client
seperator[1] = "/"; //is the name of company
seperator[2] = "("; //name of the market
seperator[5] = ":"; //ID
seperator[6] = "?"; //orderType
seperator[3] = "!@"; //realtive Time
seperator[4] = "!+"; //
seperator[7] = "+"; //quantity
seperator[8] = "@";//price
string[] result = values.Split(seperator, StringSplitOptions.None);


例如:输入字符串是
* A / AB(M!@ 12:6?SIMPLE!+ 5 + 2

输出值
    [0]:“”
    [1]:“ A”
    [2]:“ AB”
    [3]:“ M”
    [4]:“ 12”
    [5]:“ 6”
    [6]:“简单”
    [7]:“ 5”
    [8]:“ 2”


例如:输入字符串是
* A(M!@ 12?SIMPLE!+ 5 + 2 / AB:6

输出:
    [0]:“”
    [1]:“ A”
    [2]:“ M”
    [3]:“ 12”
    [4]:“简单”
    [5]:“ 5”
    [6]:“ 2”
    [7]:“ AB”
    [8]:“ 6”


我面临的问题是:我该如何称呼A是客户,AB是公司等等。

作为用户输入此信息的顺序RANDOM ...
如果他没有输入这些值中的任何一个,它将改变结果的长度?

最佳答案

使用这样的东西

SortedList<int, string> list = new SortedList<int, string>();
string[] seperator = new string[9];
seperator[0] = "*"; //is the client
seperator[1] = "/"; //is the name of company
seperator[2] = "("; //name of the market
seperator[5] = ":"; //ID
seperator[6] = "?"; //orderType
seperator[3] = "!@"; //realtive Time
seperator[4] = "!+"; //
seperator[7] = "+"; //quantity
seperator[8] = "@";//price
string val = "*A/AB(M!@12:6?SIMPLE!+5+2";

for (int iSep = 0; iSep < seperator.Length; iSep++)
list.Add(val.IndexOf(seperator[iSep]), val);

将以用户输入的任何顺序为您提供分隔符开始的位置列表,然后您可以使用子字符串来检索值

关于c# - C#-拆分字符串问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1454076/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com