2
我有一個變量,它有很多我需要排序的內容。 但是使用IndexOf和Substring,只是給了我一個並不明顯的錯誤。參數超出範圍
ArgumentOutOfRangeException:參數超出範圍。
參數名:的startIndex
錯誤是發生在 「字符串lookThroughString = ..」 行。
我的代碼只是試圖查看一個字符串,找到正確的內容,然後吐出來。
private string SCRIPT_CONTENT;
public string GetVariable(string variable_name) {
int length = 0;
string lookThroughString = SCRIPT_CONTENT.Substring(SCRIPT_CONTENT.IndexOf(variable_name));
foreach(char c in lookThroughString) {
if(c.ToString() != ";") {
length++;
}
}
return SCRIPT_CONTENT.Substring(SCRIPT_CONTENT.IndexOf(variable_name + "::"), length);
}
「腳本」 /「內容」我期待通過爲:
spellName::Fireball;
spellID::1;
我想這個功能,從輸入的變量名的開始basicly返回(在這種情況下「 SpellName'),直到第一個分號。
還沒解決問題。它將返回「腳本」中的所有內容,而不是僅返回「SpellName」行。 –
@KevinJensenPetersen你想讓它返回什麼?只是「火球」或整條線? –
實際上只有「火球」一詞,因爲這是SpellName變量包含的內容。但是我試着先開始排隊。 –