我有像
这样的文字我{love | enjoy | like {|阅读|发布在}} {stack | stackover}上。 {:D | :) | ^^ |} {他们{|是{forums | boards}那个} | {boards | forums | bbs}} 提供{免费| awesome | infomrative | new} {指南|想法|教程|帖子} (和{工具|下载|书籍}!)
in String ^ Szablon 并希望从中生成文本。
我写了一段代码:
while ((str = din->ReadLine()) != nullptr) //read from the file
{
int rndInt;
tekst=Szablon;
int i=0;
while (i<5){
Regex^ spin = gcnew Regex("{[^{}]*}");
String^ delimStr = "|";
Match^ m = spin->Match(tekst);
if ( m->Success )
{
array<Char>^ delimiter = delimStr->ToCharArray( );
array<String^>^ words;
words = m->Value->Split( delimiter );
words[0] = words[0]->Replace("{","");
words[words->Length-1] = words[words->Length-1]->Replace("}","");
Random^ r = gcnew Random();
int x=r->Next(0,words->Length);
String^ aktualny=words[x];
tekst = tekst->Replace(m->Value,aktualny);
}
else {i=8;}
}
MessageBox::Show(tekst);}
并且它正在工作,但它始终产生相同的结果