大家好我需要帮助才能获取我的字符串数组的数据是我的代码:
string playerwinnopairboth = "P ";
string bankerwinnopairboth = "B ";
string tienopairboth = "T ";
string bankerwinplayerpairnopair = "BP ";
string bankerwinbankerpairnopair = "BB ";
string playerwinbankerpairnopair = "PB ";
string playerwinplayerpairnopair = "PP ";
string tieplayerpairnopair = "TP ";
string s1 = "";
string s2 = "";
string s3 = "";
string s4 = "";
if (gametable_no == 1)
{
for (int i = 0; i < tzPlayInfo.Instance.bc_gametable_history_list.Count; i++)
{
s1 += tzPlayInfo.Instance.bc_gametable_history_list[i].r;
s1 += ",";
}
string[] newChars = s1.Split(',');
if (newChars == playerwinnopairboth)
{
o.GetComponent<UISprite>().spriteName = "layout_player_bigline-01";
NGUITools.SetActive(o, true);
}
if (newChars == bankerwinnopairboth)
{
o.GetComponent<UISprite>().spriteName = "layout_banker_bigline-01";
NGUITools.SetActive(o, true);
}
}
好的,我现在将解释每一行代码。
这行代码:
if (gametable_no == 1)
{
for (int i = 0; i < tzPlayInfo.Instance.bc_gametable_history_list.Count; i++)
{
s1 += tzPlayInfo.Instance.bc_gametable_history_list[i].r;
s1 += ",";
}
string[] newChars = s1.Split(',');
}
如果我使用foreach(string allchar in newChars){Debug.Log(allchars);}
:,会有这样的输出
P,
B,
P B,
B P,
BPP,
PB,
P,
P,
没有拆分的正常输出是:
Gametable 1历史= P,B,P B,B P,BPP,PB,P,P,
我在这里要做的是,我需要获得所有string[] newChar
值并且具有类似这样的条件
if (newChars == playerwinnopairboth)
{
o.GetComponent<UISprite>().spriteName = "layout_player_bigline-01";
NGUITools.SetActive(o, true);
}
if (newChars == bankerwinnopairboth)
{
o.GetComponent<UISprite>().spriteName = "layout_banker_bigline-01";
NGUITools.SetActive(o, true);
}
并输出类似这样的内容
图例:x =玩家赢,o =银行家赢,xo =玩家赢银行家对=牛=银行家赢家玩家对,xXx =玩家赢没有双绞者对;
所以在上面的输出中我有
P,
B,
P B,
这意味着我在记分板上的输出必须是
X
0
XXX
就像那样。
正在发生的事情是我想要的输出没有发生。有人可以帮帮我吗。
如果我不清楚请注释,我会编辑我的问题。谢谢。
答案 0 :(得分:0)
foreach (string allchars in newChars)
{
if (allchars.Contains(playerwinnopairboth))
{
//o.GetComponent<UISprite>().spriteName = "layout_player_bigline-01";
//NGUITools.SetActive(o, true);
Debug.Log("PLAYER WIN NO PAIR BOTH");
}
if (allchars.Contains(bankerwinnopairboth))
{
Debug.Log("BANKERWIN NO PAIR BOTH");
}
}
我做的是这个