これは単純に二つの部分にあなたの既存の文字列を破るためにString.Split()
方法を使用して、その後、各セクションの値をチェックの問題です:
// Example string
string test = "Name = ADP India Pvt LTD;OK = YES ";
// Split this into two sections (using the ';' as a delimiter)
var sections = test.Split(';');
// Now the first entry will be the name, so we need the section after
// the equals sign
Name.Text = sections[0].Split('=')[1].Trim();
// Based on the value of your "OK", determine if your checkbox should be checked
Ok.Checked = (sections[1].Split('=')[1].Trim()== "YES");
これは、最も安全な例ではありませんが、このような問題の解決方法について考えてください。
あなたはLINQを使用し気にしない場合は、辞書にあなたの文字列をマッピングすることにより、もう少し簡単にこの問題を解決することができます:
// Example string
string test = "Name = ADP India Pvt LTD;OK = YES";
// Map each key (e.g. "Name") and value (e.g. "ADP Index Pvt LTD")
// to an entry in a dictionary
var dictionary = test.Split(';')
.ToDictionary(k => k.Split('=')[0].Trim(),
v => v.Split('=')[1].Trim());
// Now reference what you need by it's key
Name.Text = dictionary["Name"]; // yields "ADP India Pvt LTD";
Ok.Checked = dictionary["OK"] == "YES"; // checks the checkbox if "YES"
問題は何ですか? – S4beR