Programming Question: C++ Builder String
-
rastaVnuce wrote:
Why an exception?
May be I should have added s.Length == 19, so that you do not need the count.
rastaVnuce wrote:
Shouldn't sub become "illyBob" ?
Length("illyBob") == 7. Best regards, Paul.
Jesus Christ is LOVE! Please tell somebody.
I am aware of both strings' lengths. My point is... it's much more convenient to have substring return shorter string, that throw an exception.
To hell with circumstances; I create opportunities.
-
I was assigned to update an application created with the C++ Builder 6, but after trying the IDE and realized it is not even close to VC++ 4.x, I asked and got the permission to port the whole application to WTL. I was happily doing the porting until today, when I saw something "strange" and could not understand. Investigating further, it turns out that in BCB, this code found here...[^]
String s = "My name is BillyBob";
String sub = s.SubString(12, 8);will produce sub==BillyBob. Wow! No! that should throw an exception :confused: Then the notes claim the String indexing is a 1-based not a 0-based. :mad: Is there a C++Builder user here? Are you comfortable using that string class? I think you will need a double salary. Now, I have to say goodbye to my weekend X| Best regards, Paul.
Jesus Christ is LOVE! Please tell somebody.
I did a cards game in BCB 6 in my 2nd year in college. It was the first nontrivial program that had a UI and then I liked how easy it was to design the forms. VC++ 6 was a mystery to me as I couldn't stand that class wizard way of doing things. What I absolutely hated about BCB was that if you had an error in the source code, even a missing semicolon, the Code Complete feature would not work anymore. Awful!
-
I was assigned to update an application created with the C++ Builder 6, but after trying the IDE and realized it is not even close to VC++ 4.x, I asked and got the permission to port the whole application to WTL. I was happily doing the porting until today, when I saw something "strange" and could not understand. Investigating further, it turns out that in BCB, this code found here...[^]
String s = "My name is BillyBob";
String sub = s.SubString(12, 8);will produce sub==BillyBob. Wow! No! that should throw an exception :confused: Then the notes claim the String indexing is a 1-based not a 0-based. :mad: Is there a C++Builder user here? Are you comfortable using that string class? I think you will need a double salary. Now, I have to say goodbye to my weekend X| Best regards, Paul.
Jesus Christ is LOVE! Please tell somebody.
In the one C++ module we had at university ( most of it was in java :( ) we had to use Borland Builder. Never liked it, it doesn't even seem like C/C++ to me it's more of some weird delphi / C++ hybrid thing that crashes a lot. Where possible (such as for console apps for which I wouldn't get penalized for not using VCL or whatever borland's framework was called) I used VC++ 6 on my own PC instead and just didn't use any compiler-specific extensions.
-
I was assigned to update an application created with the C++ Builder 6, but after trying the IDE and realized it is not even close to VC++ 4.x, I asked and got the permission to port the whole application to WTL. I was happily doing the porting until today, when I saw something "strange" and could not understand. Investigating further, it turns out that in BCB, this code found here...[^]
String s = "My name is BillyBob";
String sub = s.SubString(12, 8);will produce sub==BillyBob. Wow! No! that should throw an exception :confused: Then the notes claim the String indexing is a 1-based not a 0-based. :mad: Is there a C++Builder user here? Are you comfortable using that string class? I think you will need a double salary. Now, I have to say goodbye to my weekend X| Best regards, Paul.
Jesus Christ is LOVE! Please tell somebody.
Many years ago I ported an app from Turbo C++ to VC++ - one quirk of Turbo was that it had a class that encapsulated Pascal style strings where the first character of the structure is the string length, so the actual string starts at offset 1 (and is limited to 255 characters).
-
I am aware of both strings' lengths. My point is... it's much more convenient to have substring return shorter string, that throw an exception.
To hell with circumstances; I create opportunities.
rastaVnuce wrote:
it's much more convenient to have substring return shorter string, that throw an exception.
It is not about convenience, but correctness, which I think is more important to avoid problems in programming tasks. In this case, the request is beyond the content, and as in any array operation, it should not be allowed. You can easily check this before making the call to the array, if you do not want an exception. Best regards, Paul.
Jesus Christ is LOVE! Please tell somebody.
-
Many years ago I ported an app from Turbo C++ to VC++ - one quirk of Turbo was that it had a class that encapsulated Pascal style strings where the first character of the structure is the string length, so the actual string starts at offset 1 (and is limited to 255 characters).
This might explain the issue. They are most likely using the Delphi library for the C++ Builder, I do not know how many C++ Developers will like that joke. Best regards, Paul.
Jesus Christ is LOVE! Please tell somebody.
-
Yes we have BCB 6 in our project for quite some time now, and after some time you get the hang of it. You can always use the std::string class, thats the flexibility.
std:string is the lamest string class I've ever used.
Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke
-
Paul Selormey wrote:
Is there a C++Builder user here? Are you comfortable using that string class? I think you will need a double salary.
No, they are all retired with that extra cash :)
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 beta 2 - out now!
((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))leppie wrote:
No, they are all retired with that extra cash Smile
Sorry, with all the pain in my heart I have to say that I still programme in Builder 6 (well... me and 30+ other peoples in my office :~) And... to put salt in the cut, we dont have free internet access (we can only check microsoft, java, Codeproject and a few other webpages). The fear of the owners in the change of technology is amazing... Cheers!
-
In the one C++ module we had at university ( most of it was in java :( ) we had to use Borland Builder. Never liked it, it doesn't even seem like C/C++ to me it's more of some weird delphi / C++ hybrid thing that crashes a lot. Where possible (such as for console apps for which I wouldn't get penalized for not using VCL or whatever borland's framework was called) I used VC++ 6 on my own PC instead and just didn't use any compiler-specific extensions.
Dave Parker wrote:
Never liked it, it doesn't even seem like C/C++ to me it's more of some weird delphi / C++ hybrid thing that crashes a lot.
I have 3 or 4 crashes per day (in B6... in B5 had way more) And (by the law of Murphy) they happens in the worst moment possible.
-
This might explain the issue. They are most likely using the Delphi library for the C++ Builder, I do not know how many C++ Developers will like that joke. Best regards, Paul.
Jesus Christ is LOVE! Please tell somebody.
Well, Builder 5 (and 6) is builded under Delphi. By the way, the use of the strings is really a PITA in Builder (even using the AnsiString), and some things use the 0-index, others use the -1-index and a few others use the 1-index... (and try to remember all that when in the other time part job you use VB.net or C# :sigh: ) And we are not even mentioning the pointers and double pointers (and how use them with all the different data types X| ). Cheers!