+ Reply to Thread
Results 1 to 3 of 3

Character count

  1. #1
    Registered User
    Join Date
    12-18-2006
    Posts
    46

    Character count

    Here's the deal!

    I'd like to count how many characters my string contains, but without the use of Len function. To be more precise, I'd like to 'walk' through my string, and increase the counter for every letter I encounter.

    So basically, something like this:

    Please Login or Register  to view this content.
    The reason why I wan't it done this way is because at a later stage, I will want to insert a letter after the 50th character (for example).

    But, it's the end of the day, and my brain is dead.
    Help, please.

    Cheers,
    Ivan.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Ivan,

    You can't use For ... Each on a string. It can only be used with Collection Objects. The strings length is part of the string itself. You can return that value using either VBA's Len() function or the API's lenstr function. Using the length is the only way you can "walk" through the string. Here is an example of how to inset a string or character at the 50th character position in a string.

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross
    Last edited by Leith Ross; 03-19-2007 at 12:46 PM.

  3. #3
    Registered User
    Join Date
    12-18-2006
    Posts
    46
    Hi,

    i knew For..Each doesn't work this way, it was just the way of describing my idea. It's clear to me now, after your answer.

    Thanks for the reply!

    Cheers,
    Ivan.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1