是的,你可以通過字符重複字符:
using System;
class Program
{
static void Main()
{
const string s = "Hello!";
// Option 1
foreach (char c in s)
{
Console.WriteLine(c); // Your treatment here
}
// Option 2
for (int i = 0; i < s.Length; i++)
{
Console.WriteLine(s[i]); // Your treatment here
}
}
}
你可以用這個來連接(治療porcess):
if (some_condition) text1 += s[i];
然後在Your treatment here
部分,你可以通過使用C#提供的基本隨機函數。只要你不改變seed
,您可以檢索用於生成子,可能恢復它的序列......
可能是,例如,類似的東西:
int seed = 12;
List<int> lst = new List<int>();
// Repeat that until you processed the whole string
// At the mean time, skip the characters already indexed
while (lst.Count != s.Length) {
int n = new Random(seed).Next(0, s.Length);
if (!lst.Contains(n)) {
text1 += s[n];
lst.Add(n);
}
}
在結束lst
是您恢復過程的關鍵。
然後您生成子字符串的方式,以及恢復原始字符串的算法也取決於您......您是完全免費的。
注:關於與chunks
交易,請參閱Simon
的答案。
一切皆有可能 –
什麼是'text1的[]'應該是什麼?帶有「AOCN」的字符串或者.. um .. no。的數組。 –
@GrantWinney編輯了這個問題,它假設它是一個字符串數組,對不起混淆 – user1461511