CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2004
    Posts
    19

    Unhappy Getting the length of a string

    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

  2. #2
    Join Date
    Jul 2003
    Location
    Sunshine Coast, Australia
    Posts
    132

    Re: Getting the length of a string

    get_Length is a property, so the way to access it is to use Length

    Code:
    szSourceLine->Length;
    Properties work in the following way. If you define a function as a property as below

    Code:
    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

    Code:
    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
    Lloydy

  3. #3
    Join Date
    Nov 2004
    Posts
    19

    Unhappy Re: Getting the length of a string

    Thanks,

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

    Danielle

  4. #4
    Join Date
    Jul 2003
    Location
    Sunshine Coast, Australia
    Posts
    132

    Re: Getting the length of a string

    Don't forget to rate the post
    Lloydy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured