TCPClientを使用してLAN経由でメッセージ(配列のリスト)を送信しているので、次のように分離しました。
- 組み合わせのある配列要素:
string arr_sep = "[s{p(a)c}e]";
- 組み合わせで要素を一覧表示します。
string list_sep = "[n|e|w)";
正規表現string
を使用するために次の行を解読するにはどうすればよいですか?List<string[]>
string tessst = "abra[s{p(a)c}e]kada[s{p(a)c}e]bra[n|e|w)hel[s{p(a)c}e]oww[s{p(a)c}e]een";
これが私がやろうとしたことです:
string tessst = "abra[s{p(a)c}e]kada[s{p(a)c}e]bra[n|e|w)hel[s{p(a)c}e]oww[s{p(a)c}e]een";
List<string[]> splited2 = new List<string[]>();
if (tessst.Length > 0)
{
List<string> splited1 = new List<string>(Regex.Split(tessst, "[^a-zA-Z]+")); //[s{p(a)c}e]
for (int i = 0; i < splited1.Count; i++)
{
splited2.Add(Regex.Split(splited1[i], "[^a-zA-Z]+")); // [n|e|w)
}
}
//splited2 is the result!
残念ながら、正規表現は完全に壊れています-どうすれば修正できますか?より良いアプローチはありますか?
期待される結果:
List<string[]> result = new List<string[]>();
result.Add(new string[]{"abra", "kada", "bra"});
result.Add(new string[]{"hel", "oww", "een"});
編集:修正
List<string[]>
データを受信すると、通常はバイトを1024に制限しますが、 !の50エントリすべてを取得するにはそれだけでは不十分です。
バイト数を10000まで増やしたところ、すべての情報がLANを経由するようになりました。string[]
の50をシリアル化するには3499バイトかかりますList<string[]>
。将来的には、リストで最大900のエントリを使用する予定なので、次のものが必要になると想定しても問題ありません。
(3499/50)* 900=63000バイトでデータをシリアル化!!
問題は、データを一度に送信するのは安全/安全ですか?これが私が受け取るために使用するコードです:
string message = "";
int thisRead = 0;
int max = 10000; // from 1024 to 10000
Byte[] dataByte = new Byte[max];
using (var strm = new MemoryStream())
{
thisRead = Nw.Read(dataByte, 0, max);
strm.Write(dataByte, 0, thisRead);
strm.Seek(0, SeekOrigin.Begin);
using (StreamReader reader = new StreamReader(strm))
{
message = reader.ReadToEnd();
}
}
List<string[]> result = new JavaScriptSerializer().Deserialize<List<string[]>>(message );
そしてそれは送ることです:
List<string[]> list= new List<string[]>();
list = browser_ex.GetMusicListSer(); // 50 list elements
string text_message = new JavaScriptSerializer().Serialize(list);
MemoryStream Fs = new MemoryStream(ASCIIEncoding.Default.GetBytes(text_message));
Byte[] buffer = Fs.ToArray();
Nw.Write(buffer, 0, buffer.Length); // 3499 bytes
最大バイト数を10万バイトに増やして、この問題を完全に忘れることはできますか?別の解決策があるはずです...私は信じています。