如何将一个未知长度的有规律字符串如“ww,dd,gg,tt,gg”分割并存储。

lg75 2001-07-20 02:12:41
加精
例如
分割后存在TStringList内或String[?]内。
String[0]="ww"
String[1]="dd"
String[2]="gg"
String[3]="tt"
String[2]="gg"
最好是在TStringList内,

另外如何判断一维数组的大小?
请提供BCB代码,谢谢!
...全文
198 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
68467263 2001-08-19
  • 打赏
  • 举报
回复
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int i=0;
char kk[]="st ch 1";
do
{
Edit1->Text=Edit1->Text+"(第"+i+"列)";
Edit1->Text=Edit1->Text+kk[i];
i=i+1;
}
while (i!=strlen(kk));
}
lg75 2001-07-26
  • 打赏
  • 举报
回复
给分了
书生 2001-07-20
  • 打赏
  • 举报
回复
我前不久写一个时间函数的一段相关代码。希望对你有帮助。(意思不完全相同啊)

//ctDList 排序
int loc;
TList *aa;
aa=new TList();

struct bb* x;

//delete bb;
//delete aa;

//取出字符串中的数值----号表
for(int i=0;;i++)
{
x=new struct bb;
loc=ctDList.Pos(";");
if(loc==0)
{
int length=ctDList.Length();
x->index=i;
x->num=StrToInt(ctDList.SubString(1,length));
aa->Add(x);
ctDList="";
break;
}
else
{
x->index=i;
x->num=StrToInt(ctDList.SubString(1,loc-1));
aa->Add(x);
ctDList=ctDList.SubString(loc+1,ctDList.Length()-loc);
}
}//取出了字符串中的数值

//冒泡法排序----号表
for(int i=0;i<aa->Count;i++)
{
int temp;
struct bb* y1;
y1=(struct bb*)aa->Items[i];
int y11=y1->num;
for(int j=0;j<aa->Count;j++)
{
struct bb* y2;
y2=(struct bb*)aa->Items[j];
int y22=y2->num;
if(y22>y11)
{
temp=y2->num;
y2->num=y1->num;
y1->num=temp;
}
}
}
//数值排序完毕--准备变成字符串--号表

//转化成字符串--号表
for(int i=0;i<aa->Count;i++)
{
struct bb*y;
y=(struct bb*)aa->Items[i];
if(i==aa->Count-1)//最后一项
{
ctDList=ctDList+IntToStr(y->num);
}
else
{
ctDList=ctDList+IntToStr(y->num)+";";
}
}
Edit6->Text=ctDList;
//ctDList排序完毕

//ctWList排序----周表
int wlist=(ctWList.Length()+1)/2;
for(int j=1;j<=wlist;j++)
{
for(int i=1;i<=wlist;i++)
{
char temp;
if(ctWList.SubString(i*2-1,1)>ctWList.SubString(j*2-1,1))
{
/*temp=ctWList.SubString(i*2-1,1);
ctWList.SubString(i*2-1,1)=ctWList.SubString(j*2-1,1);
ctWList.SubString(j*2-1,1)=temp;*/
temp=ctWList[i*2-1];
ctWList[i*2-1]=ctWList[j*2-1];
ctWList[j*2-1]=temp;

}
}
}
Edit7->Text=ctWList;
//ctWList排序完毕


玉笛书生
dbxmcf 2001-07-20
  • 打赏
  • 举报
回复
怎么贴出来就全没格式了?
dbxmcf 2001-07-20
  • 打赏
  • 举报
回复
这是我vc代码里挑出来的
dbxmcf 2001-07-20
  • 打赏
  • 举报
回复
示例代码:不过用于分割数字,但是string也一样的:
const int Max=1024;
char p[Max],p1[Max];
m_strShow+=",";
sprintf(p,"%s",m_strShow); //CString
int iCount=0;
m_strOut="";
m_dblSun=0.0;
double d[10];//辨认出的数值
int iNum=0;
for (int i=0;p[i]!='\0';i++)
{
iCount++;
if (p[i]==',')
{
for (int j=0;j<=iCount-2;j++)
p1[j]=p[i-iCount+j+1];
p1[j]='\0';
d[iNum]=atof((const char*)p1);
m_dblSun+=atof((const char*)p1);
m_strOut+=p1; //CString
m_strOut+=" ";
iCount=0; //CEdit
iNum++;
}
}

char p2[Max];
for (i=0;i<=iNum-1;i++)
{
sprintf(p2,"%5.5lf",d[i]);
m_strResult+=p2;
m_strResult+=";";
}
火鸟33 2001-07-20
  • 打赏
  • 举报
回复
自己定义分割符号如#
wjzhuang 2001-07-20
  • 打赏
  • 举报
回复
什么样的规则?
长度不知道没关系,lenght可以获得
获得长度,然后根据规则来申请一维数组
然后读取就可以了

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧