views:

18

answers:

2

I have a ASP has a Function that converts

ä to &auml so far so good.

I have lets say space for 10 char's if there are more cut them of if there are less fill the space up with &nbsp's. . Like this:

test &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp

but if i say "täst" it does this:

te &auml t &nbsp

It interprets the &auml not as one char it looks at it as 6 chars. Is there a clever way around that? This problem messes up my design because I need the right count of spaces. The whole thing goes into a big select box.

Of you have to add a ; at the end of ever &... I could add them because the Editor would really interprt them.

+1  A: 

Could you count the characters before you convert them?

So with the example of "täst", you would determine that you will need 6 &nbsp's. then convert the characters (te &auml t), then append the &nbsp's (te &auml t &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp).

Tester101
+1  A: 

Something like ? Don't shoot me of you get small errors, I can't test it now (don't have a server here) so so it's coded from heart:

function CountChars ( byval s )

dim i, inAmp, Result

   Result = 0
   inAmp = False
   for i = 1 to len(s)
      select case mid(s,i,1)
         case "&" 
            Result = Result + 1
            inAmp = True
         case ";"
            if inAmp then inAmp = False
         case else
             if not inAmp then Result = Result + 1
      end select
   next
   CountChars = Result
end function
Edelcom