Re: Arabic or Chinese characters in a URL link give error copying
- From: "Tony Proctor" <tony_proctor@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 3 Aug 2005 15:14:33 +0100
....and what if your text contains a real "?" Ted (Chr(63) is merely a
question mark).
What you're trying to do there (implicitly) is convert the Unicode text to
the active ANSI character set, and then search for "?". If your locale isn't
Arabic/Chinese then the associated "wide" Unicode characters will have been
replaced by a "?" substitution character, but that doesn't uniquely identify
where a wide character was.
What I suggested above was simply something like:
Function ContainsWideChars(ByRef inString As String) As Boolean
Dim iCh As Integer
For iCh = 1 To Len(inString)
If AscW(Mid$(inString, iCh, 1)) > &HFF Then
ContainsWideChars = True
Exit For
End If
Next iCh
End Function
This is a very simple bit of code but does exactly the same as Mike's
Tony Proctor
"Ted" <2000@xxxxxxxxxx> wrote in message
news:O6erRJDmFHA.2156@xxxxxxxxxxxxxxxxxxxxxxx
> >Ted, let me know if this makes any sense, or you want an example]
> Example would help, thanks
>
> I tried this one and it seems to work
> If instr(afile, Chr(63)) > 0 then goto iSkip
>
>
>
> "Tony Proctor" <tony_proctor@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message
> news:eZ4tC8BmFHA.2484@xxxxxxxxxxxxxxxxxxxxxxx
> >I don't understand what advice you're giving here Mike. All VB String
data
> > contains Unicode characters - by definition. If they contain anything
else
> > then the program is doing something wrong.
> >
> > I interpreted the OP's problem as really the need to display the foreign
> > characters of the file name rather than the "???" substitution
characters.
> > If his locale was Arabic or Chinese then I would have expected no
problem.
> > Hence, it sounds like his locale is set to something else.
> >
> > I know he asked to be able to detect Arabic/Chinese characters so that
he
> > can skip those files but that's just a lesser solution ;-) Anyway, that
> > would be easy to infer by just scanning each character of the filename
and
> > checking for AscW(sCh)>&hFF, i.e. whether any character has a Unicode
> > value
> > outside the 8-bit range. This will actually detect any character that
> > isn't
> > used by West Europe or N/S America since the low 8-bit range of the
> > Unicode
> > set is identical to the ISO 8859/1 character set, which is very similar
to
> > the Windows Latin 1 set (aka code page 1252). [Ted, let me know if this
> > makes any sense, or you want an example]
> >
> > Tony Proctor
> >
> > "Mike D Sutton" <EDais@xxxxxxxx> wrote in message
> > news:el24NuBmFHA.1148@xxxxxxxxxxxxxxxxxxxxxxx
> >> > How can I detect if a file has Arabic or Chinese characters, so
> >> > I can skip it while copying ?
> >> >
> >> > if I do this
> >> > Text1.Text = Dir("f:\test1\*.url")
> >> > Kill "f:\test1\" & Text1.Text
> >> >
> >> > I get error deleting and I get a file name
> >> > ????? ?????? ??????.url
> >> > in the text box.
> >>
> >> If you need to detect whether the string contains Unicode data then try
> > one of these two methods:
> >>
> >> '***
> >> Private Declare Sub GetByte Lib "MSVBVM60.dll" Alias _
> >> "GetMem1" (ByRef inSrc As Any, ByRef inDst As Byte)
> >>
> >> Private Function IsUnicodeString(ByRef inString As String) As Boolean
> >> Dim LoopChars As Long
> >> Dim ReadPtr As Long
> >> Dim TempByte As Byte
> >>
> >> ReadPtr = StrPtr(inString) + 1
> >> For LoopChars = 0 To Len(inString) - 1
> >> Call GetByte(ByVal ReadPtr, TempByte)
> >>
> >> If (TempByte) Then
> >> IsUnicodeString = True
> >> Exit For
> >> End If
> >>
> >> ReadPtr = ReadPtr + 2
> >> Next LoopChars
> >> End Function
> >> '***
> >>
> >> '***
> >> Private Declare Function VarPtrArray Lib "MSVBVM60.dll" Alias "VarPtr"
> > (ByRef Ptr() As Any) As Long
> >> Private Declare Sub PutDWord Lib "MSVBVM60.dll" Alias "PutMem4" (ByRef
> > inDst As Any, ByVal inSrc As Long)
> >>
> >> Private Type SAFEARRAYBOUND
> >> cElements As Long
> >> lLbound As Long
> >> End Type
> >>
> >> Private Type SAFEARRAY1D
> >> cDims As Integer
> >> fFeatures As Integer
> >> cbElements As Long
> >> cLocks As Long
> >> pvData As Long
> >> rgsaBound As SAFEARRAYBOUND
> >> End Type
> >>
> >> Private Function IsUnicodeString(ByRef inString As String) As Boolean
> >> Dim ArrDesc As SAFEARRAY1D
> >> Dim ArrPtr As Long
> >> Dim StrArr() As Integer
> >> Dim LoopChars As Long
> >>
> >> If (Len(inString) <= 0) Then Exit Function
> >>
> >> With ArrDesc ' Setup temporary array descriptor
> >> .cbElements = 2
> >> .cDims = 1
> >> .rgsaBound.lLbound = 0
> >> .rgsaBound.cElements = Len(inString)
> >> .pvData = StrPtr(inString)
> >> End With
> >>
> >> 'Get array pointer and write new descriptor
> >> ArrPtr = VarPtrArray(StrArr())
> >> Call PutDWord(ByVal ArrPtr, ByVal VarPtr(ArrDesc))
> >>
> >> For LoopChars = 0 To Len(inString) - 1 ' Check high bytes
> >> If (StrArr(LoopChars) And &HFF00&) Then Exit For
> >> Next LoopChars
> >>
> >> IsUnicodeString = LoopChars < Len(inString)
> >> Call PutDWord(ByVal ArrPtr, 0&) ' Clean up
> >> End Function
> >> '***
> >>
> >> The second method should be faster on long strings, but using a
slightly
> > nasty hack to get at the string data which some
> >> may not want to use.
> >> Hope this helps,
> >>
> >> Mike
> >>
> >>
> >> - Microsoft Visual Basic MVP -
> >> E-Mail: EDais@xxxxxxxx
> >> WWW: Http://EDais.mvps.org/
> >>
> >>
> >
> >
>
>
.
- References:
- Re: Arabic or Chinese characters in a URL link give error copying
- From: Mike D Sutton
- Re: Arabic or Chinese characters in a URL link give error copying
- From: Tony Proctor
- Re: Arabic or Chinese characters in a URL link give error copying
- Prev by Date: Re: Bitwise operating...is that the term?
- Next by Date: Re: multithreading
- Previous by thread: Re: Arabic or Chinese characters in a URL link give error copying
- Next by thread: Combine 2 Word Documents into one
- Index(es):
Relevant Pages
|
Loading