Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 检查字符串是否包含匹配的字符串属性_C#_Android_Unity3d - Fatal编程技术网

C# 检查字符串是否包含匹配的字符串属性

C# 检查字符串是否包含匹配的字符串属性,c#,android,unity3d,C#,Android,Unity3d,例如,我有以下数据: P, P, P, B, B, T, T, T, P, P 然后我通过这样做得到: for (int i = 0; i < gametable_history_list.Count; i++) { newString[0] += gametable_history_list[i].r; newString[0] += ","; } string[] newChars = newString[0].Split(','); 显示:p,p,p else如果

例如,我有以下数据:

P, P, P, B, B, T, T, T, P, P
然后我通过这样做得到:

for (int i = 0; i < gametable_history_list.Count; i++)
{
    newString[0] += gametable_history_list[i].r;
    newString[0] += ",";
}
string[] newChars = newString[0].Split(',');
显示:
p,p,p

else如果(newChars正在更改){

显示:
B,B

else如果(newChars正在更改){

显示:
T,T,T

else如果(newChars正在更改){

显示:
p,p

它必须类似于以下输出:

我得到了什么

这里我真正的问题是,我需要对每个相同的数据(p,p,p)进行
变换。localPosition
,然后如果数据像(B,B)那样变化,它必须移动到另一列,这就是我需要移动x和y轴的列。

这里是一个(部分)示例(我不知道如何创建显示的文本,也不知道它是如何定位的,因此我只能建立一个非常基本的示例,并用注释告诉您如何放置它们)

::更新::

我找到了您之前的问题,并将您提供的代码与Nand gopal的答案一起添加到此答案中

//calling this with "PPPBBTTTPP" yields ["PPP","BB","TT","PP"]
//keep in mind that this is a separate method
//so it should go *outside* the create, initialise, and update methods

string[] GroupString(string inputString){
     string result = " ";
     foreach (var c in inputString)
     {
         result = result + (result.Last() == c ? "" : " ") + c;
     }
     return result.Trim().Split(' ');
}

//the logic for creating your table :

string newString = "";

for (int i = 0; i < gametable_history_list.Count; i++)
{
    newString += gametable_history_list[i].r;
}

string[] groupedString = GroupString(newString);

//you can now iterate over groupedString

for(int x=0; x < groupedString.length; x++)
{
    for(int y=0; y < groupedString[x].length; y++)
    {

        //display groupedString[x] at position determined using X and Y
        //(i don't know how you do this since you did not provide example code for this part)

        //update : assuming your previous question is related : 
        GameObject o = Instantiate(prefab_big_road[0]) as GameObject;
        o.transform.SetParent(pos_big_road[0]);
        o.transform.localScale = Vector3.one;
        //the positioning happens here : 
        o.transform.localPosition=new Vector3 (o.transform.localPosition.x+x,o.transform.localPosition.y+y,o.transform.localPosition.z);

        if (allchars.Contains(playerwinnopairboth))
        {
            o.GetComponent<UISprite>().spriteName = "layout_player_bigline-01";
            NGUITools.SetActive(o, true);
        }
        if (allchars.Contains(bankerwinnopairboth))
        {
            o.GetComponent<UISprite>().spriteName = "layout_banker_bigline-01";
            NGUITools.SetActive(o, true);
        }

    }
}
//用“PPPBBTTTPP”调用这个函数会产生[“PPP”、“BB”、“TT”、“PP”]
//请记住,这是一种单独的方法
//所以它应该在create、initialise和update方法之外
字符串[]组字符串(字符串输入字符串){
字符串结果=”;
foreach(inputString中的var c)
{
结果=结果+(result.Last()==c?“:”)+c;
}
返回结果.Trim().Split(“”);
}
//创建表的逻辑:
字符串newString=“”;
对于(int i=0;i
您能确认第三次输出是2或3'T'吗?@KaushalGosaliya对其进行了编辑。很抱歉,据我所知,您只想显示与最新字符相同的字符,从该组中的第一次出现到结束,对吗?@TimothyGroote类似的内容,先生?您能准确显示您希望的输出吗明白了。我留下一件事让你们去弄清楚:我不确定装置的Y轴是否颠倒了,所以你们的桌子可能会颠倒。先生,我不小心从c 4升级到了c 7.0。我的项目还好吗???该死的imnervous@TheGinxx009嗯,这种情况很快就升级了。我以前从未尝试过,但我最好的猜测是C#7代码不会在MONO上运行,所以我很抱歉i’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
//calling this with "PPPBBTTTPP" yields ["PPP","BB","TT","PP"]
//keep in mind that this is a separate method
//so it should go *outside* the create, initialise, and update methods

string[] GroupString(string inputString){
     string result = " ";
     foreach (var c in inputString)
     {
         result = result + (result.Last() == c ? "" : " ") + c;
     }
     return result.Trim().Split(' ');
}

//the logic for creating your table :

string newString = "";

for (int i = 0; i < gametable_history_list.Count; i++)
{
    newString += gametable_history_list[i].r;
}

string[] groupedString = GroupString(newString);

//you can now iterate over groupedString

for(int x=0; x < groupedString.length; x++)
{
    for(int y=0; y < groupedString[x].length; y++)
    {

        //display groupedString[x] at position determined using X and Y
        //(i don't know how you do this since you did not provide example code for this part)

        //update : assuming your previous question is related : 
        GameObject o = Instantiate(prefab_big_road[0]) as GameObject;
        o.transform.SetParent(pos_big_road[0]);
        o.transform.localScale = Vector3.one;
        //the positioning happens here : 
        o.transform.localPosition=new Vector3 (o.transform.localPosition.x+x,o.transform.localPosition.y+y,o.transform.localPosition.z);

        if (allchars.Contains(playerwinnopairboth))
        {
            o.GetComponent<UISprite>().spriteName = "layout_player_bigline-01";
            NGUITools.SetActive(o, true);
        }
        if (allchars.Contains(bankerwinnopairboth))
        {
            o.GetComponent<UISprite>().spriteName = "layout_banker_bigline-01";
            NGUITools.SetActive(o, true);
        }

    }
}