Click to See Complete Forum and Search --> : Getting the length of a string


dmacnevin
November 23rd, 2004, 07:44 PM
Hey there,

I'm trying to get the length of a string so that I can determine when to stop copying items from it.

I have a string

System::String *szSourceLine;

which I load with a line from a file. (This is working correctly).
I am trying to find the length of this atring. I tried using both

szSourceLine->get_Length() and szSourceLine->Length();

but it gives me the error:
"term does not evaluate to a function taking 0 arguments"
Does anyone have any information about this?


Or if you have any information on another way to determine if you are at the end of a string, that would also be helpful. I was using

szSrcLine->get_Chars(i);

to get the characters out of the string, and thenprocess them. But once I reach the end of the string, I run into errors since I am accessing over the length of the string.

If you have any ideas on this, please let me know. It would be greatly appreciated.

Thanks
Danielle

lloydy
November 23rd, 2004, 07:58 PM
get_Length is a property, so the way to access it is to use Length


szSourceLine->Length;


Properties work in the following way. If you define a function as a property as below


public __gc class MyClass
{
private: int variable;
//Note : you cannot use get_varaible
public:__property int get_Variable(){return variable);
public:__property int set_Variable(int NewVaraible){_variable = NewVaraible);
};


you then use it like this


MyClass* MyInstance = new MyClass();

MyInstance ->Variable = 6;

//more stuff

int Val = MyInstance->Variable;


I hope this clears this up for you. If not, there is a lot on __property in MSDN

Cheers

dmacnevin
November 23rd, 2004, 09:45 PM
Thanks,

your suggestion worked. I'm also going to take a look at __property in MSN this week.

Danielle

lloydy
November 23rd, 2004, 11:31 PM
Don't forget to rate the post :wave: