[Qt-interest] indexOf empty substring
Srikanth Bemineni
srikanth.bemineni at gmail.com
Wed Feb 4 05:53:05 CET 2009
Can you please explain me this
I want to know the defintion of an empty string.
My problem looks like as if i am looking for a zero in one in terms of maths
I havent went through the code of QString.I assume QString would look like
this.
MString
{
MString()
{
strptr = 0;
size =0;
}
~MString()
{
}
void operator=( const char* ptr )
{
int i = strlen(ptr);
if( i > size )
{
delete[] strptr;
resize( i );
}
strncpy( ptr , strptr , i );
strptr[i+1] = '\0';
}
void resize( int i )
{
strptr = new char[i + 1];
}
char* strptr;
int size;
};
Not the complete code but in similar lines with other operator
functionality.The solution is I will resize my char buffer as needed.
In Basic C char array is used to store characters
'\0' is represented as a null and every char array ends with a null. Does
QString has null or an unintialized char pointer in the string buffer if is
is empty?.
if we apply this rule assuming that the empty string contians a null empty
char array. Then the indexOf() should return me the length of the string +1
What does the empty string buffer contain in a QString?
On Tue, Feb 3, 2009 at 10:14 PM, <andrew.m.goth at l-3com.com> wrote:
> Srikanth Bemineni wrote:
> > I want to know why an indexof() of an empty substring on a
> > string gives me 0.
>
> Every string begins and ends with an empty string, and there is an empty
> string between each pair of adjacent characters. So an empty string can
> be found anywhere you look for it.
>
> --
> Andy Goth
> <amgoth at link.com>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
--
_/\_
With Regards
SB Angel Warrior
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090203/6194d708/attachment.html
More information about the Qt-interest-old
mailing list