Spanish characters have no length? 
Author Message
 Spanish characters have no length?

I'm trying out RB5 demo for Windows.

If I read in a string that consists of only a spanish punctuation character
(the upside-down ? or !) the len() function returns a length of 0. The
string shows up correctly in the de{*filter*}, and the ascB function yields a
number in the expected 128-255 range (the asc function gives some number >
100K).

Is this a bug? Or am I misunderstanding something? Is there a workaround
(other than if len(str) = 0 then str.len = 1)?

By the way, the Windows hosted version seems to avoid the problem I had on
RB4.5 compiling for windows where textfiles weren't being written to disk or
registered in directories fast enough. I haven't tried RB5Mac cross
compiling yet; maybe it's a RB5 improvement overall.

Thanks,
Ron



Tue, 01 Nov 2005 00:12:12 GMT  
 Spanish characters have no length?

Quote:

> I'm trying out RB5 demo for Windows.

> If I read in a string that consists of only a spanish punctuation character
> (the upside-down ? or !)...

How should RB know which encoding this string has?

Mfg
Christian

--
Four thousand functions in one REALbasic plug-in. The MBS Plugin.

<http://www.monkeybreadsoftware.de/realbasic/plugins.html>



Tue, 01 Nov 2005 07:27:48 GMT  
 Spanish characters have no length?

Quote:
> Christian asks: How should RB know which encoding this string has?

I 'm not an expert, but I don't see how the text encoding plays a role here.
The string (consisting of only a spanish punctuation mark) is displayed
correctly in the de{*filter*}, passing the string to ascB function gives the
correct ascii code (161 or 191 in Windows), but passing the string to the
len function returns a len of zero.

For now, I'll just try a kludge, e.g. if ascB(str) = 161 or...191) then
str_len = 1, but sometimes things that I think are bugs turn out to be my
own lapses of knowledge.

Thanks,
Ron



Wed, 02 Nov 2005 01:34:32 GMT  
 Spanish characters have no length?

Quote:

>> Christian asks: How should RB know which encoding this string has?

> I 'm not an expert, but I don't see how the text encoding plays a role here.
> The string (consisting of only a spanish punctuation mark) is displayed
> correctly in the de{*filter*}, passing the string to ascB function gives the
> correct ascii code (161 or 191 in Windows), but passing the string to the
> len function returns a len of zero.

> For now, I'll just try a kludge, e.g. if ascB(str) = 161 or...191) then
> str_len = 1, but sometimes things that I think are bugs turn out to be my
> own lapses of knowledge.

> Thanks,
> Ron

I made a test:
  dim s as string

  s="?"
  msgBox str(len(s))

And the output was "1".

So I don't really understand what you did wrong (if any)...

--
Didier

http://www.*-*-*.com/

dda (o) sungnyemun . org



Wed, 02 Nov 2005 03:19:32 GMT  
 Spanish characters have no length?

Quote:

> If I read in a string that consists of only a spanish punctuation character
> (the upside-down ? or !) the len() function returns a length of 0.

You must have "read in" the string in some way that doesn't let RB know
what encoding this string of bytes is.  So, it can make a guess, but its
guess is likely to be wrong -- and if wrong, it may not be able to find
a valid length at all.

This could happen, for example, if you read in your bytes from a file.

The solution is to tell RB explicitly what encoding you have in mind,
something like this:

  s = DefineEncoding(s, Encodings.ISOLatin1)  // or whatever

Now, RB knows how to interpret these bytes as text, which means that
text-oriented functions (like Len -- compare with LenB) will work
correctly.

Cheers,
- Joe

,------------------------------------------------------------------.
|    Joseph J. Strout         Check out the Mac Web Directory:     |

`------------------------------------------------------------------'



Fri, 04 Nov 2005 09:52:43 GMT  
 Spanish characters have no length?
Okay. I get it now. Thanks to Christian and Joe and others who offered
enlightenment.

Ron



Fri, 04 Nov 2005 22:48:54 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Returning a dynamic character array based on input length

2. variable-length character array.

3. Find the length of a character field

4. maximum supported length of characters in a table

5. fixed length character array passed as a real argument

6. Unknown character length

7. Length of Character Strings

8. PARAMETER for character length declaration

9. Dynamic character length?

10. Fortran subroutine characters args and their lengths and C

11. library v. module character function lengths

12. Assumed length character functions in modules

 

 
Powered by phpBB® Forum Software