Find text in string...

Hi,

I want to find a string which should have been added before in a while procedure:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
CString strLocalText;
strLocalText = [22 CHarge/Serie];

CString strLeft;
CString strRight;
CString strAnz=S.GTM("Anz.",nSprache);
CString strDat=S.GTM("Ablaufdatum",nSprache);
Cstring strLocalText2;
CString strLTTemp=strLocalText;
strLocalText="";
strlocaltext2=""
if(strLTTemp.GetLength()>0){
while(strLTTemp.GetLength()>0){
  CString strLTLine=H.ExtractFirstLine(strLTTemp);
  if(strLTLine.GetLength()>0){
     CString strLotNr=H.ExtractFirstElementFromLine(strLTLine,":");
     CString strAnz2=H.ExtractFirstElementFromLine(strLTLine,":");
     CString strDat2=H.ExtractFirstElementFromLine(strLTLine,":");
     strAnz2.TrimLeft();
     strDat2.TrimLeft();

     strLocalText2=strLocalText + strLotNr + "   ";
     if(strAnz2.GetLength()>0){strLocalText2=strLocalText2 + strAnz + ":" + strAnz2 +"   ";};
      if(strDat2.GetLength()>0){strLocalText2=strLocalText2 + strDat + ":" + strDat2;};
};
strLocalText2=strLocalText2 + "\r\n";

int ind = strlocaltext2.IndexOf(S.GTM("Serien-/Chargennummer",nSprache));
if (ind > -1)
{}
else
{
strLocalText2=S.GTM("Serien-/Chargennummer",nSprache) + ":" + strLocalText2;
}

};
strlocaltext=strlocaltext2;
};


Now when I have two serial numbers, I can write

1
2
3
4
5
6
7
8
9
10

};
strLocalText2=strLocalText2 + "\r\n";
strLocalText2=S.GTM("Serien-/Chargennummer",nSprache) + ":" + strLocalText2;
};
strlocaltext=strlocaltext2;
};

[code]
Instead of:

strLocalText2=strLocalText2 + "\r\n";

int ind = strlocaltext2.IndexOf(S.GTM("Serien-/Chargennummer",nSprache));
if (ind > -1)
{}
else
{
strLocalText2=S.GTM("Serien-/Chargennummer",nSprache) + ":" + strLocalText2;
}

};
strlocaltext=strlocaltext2;
};[/code]

When I write that, the program writes e.g.:
SerialNumber: SerialNumber:090010090 Qty: 1 Exp.Date: 12.12.2012
090010091 Qty: 4 Exp.Date 13.12.2012

What is wrong? I want that in both lines stands:

SerialNumber: ..... Qty: ... Exp.Date: ...



How is this possible with my code?

Kindest Regards and thanks
Daniel
Well I think, that was my fault, it is not C++, it's C#...

Hope anyone of you guys can help me!

KR
Daniel
well look for the C# string library, if it's the same as C++ std::string library, then find() and find_first_of() can be used.

http://www.cplusplus.com/reference/string/string/
well that means that I have to use it like this:

1
2
3
4
5
6
7

if (strLocalText2.find() = S.GTM("Serien-/Chargennummer",nSprache))

{
command
}
No that's not how find is used.
Can you just tell me how to use it correctly?

Thank you in advance!
No I can't because at some point your going to have to start thinking like a programmer and start looking up information for yourself, I have given you a link I suggest you use it. Although this is only going to be helpful if C# and C++ use the same class libraries.
Last edited on
If you want you can go really low level and just write a string searching class for yourself that takes a char* and searches letter by letter for the cstring in current string.
Well...I can think like a programmer, but if an error occures and the program crashes...how can I proceed?

I hope that you'll be so kind and help me a little bit further...
but if an error occures and the program crashes...how can I proceed?


search for reasons of why the error occured!?!...

http://msdn.microsoft.com/en-us/library/ms228630%28VS.80%29.aspx <just an guess>
Last edited on
Incubbus wrote:
search for reasons of why the error occured!?!...


QFT
qft?... eatable?...
QFT = Quoted For Truth
Topic archived. No new replies allowed.