< s c r i p t language=vb runat=server id="modStrTools"> ' 發展單位:風禹科技驗證有限公司 ' 撰寫人:鄭子璉(Tzu-Lien, Cheng, 璉璉) ,成大水利博肄,微軟最有價值專家 ' Web: http://tlcheng.twbbs.org/TLCheng/ E-Mail: qvb3377@ms5.hinet.net ' -------------------------------------------------------------------------------------- Public Enum enuStandardCodePages As Integer SCP_CP_ACP = 0 ' 預設為 ANSI 字碼頁 SCP_CP_OEMCP = 1 ' 預設為 OEM 字碼頁 SCP_CP_MACCP = 2 ' SCP_CP_THREAD_ACP = 3 ' 目前執行緒的 ANSI 字碼頁 SCP_CP_SYMBO = 42 ' SYMBOL 轉譯 SCP_ibm852 = 852 ' Central European (DOS) SCP_ibm866 = 866 ' Cyrillic (DOS) SCP_windows_874 = 874 ' Thai SCP_Japanese = 932 ' 日文 SCP_cseucpkdfmtjapanese = 932 ' Japanese (EUC) SCP_csiso2022jp = 932 ' Japanese (JIS_Allow 1 byte Kana) SCP_csshiftjis = 932 ' Shift_JIS SCP_extended_unix_code_packed_format_for_japanese = 932 ' Japanese (EUC) SCP_iso_2022_jp = 932 ' Japanese (JIS) SCP_ms_kanji = 932 ' Shift_JIS SCP_shift_jis = 932 ' Shift_JIS SCP_x_euc = 932 ' Japanese (EUC) SCP_x_euc_jp = 932 ' Japanese (EUC) SCP_x_sjis = 932 ' Shift_JIS SCP_chinese = 936 ' 簡體中文 SCP_csgb2312 = 936 ' Chinese Simplified (GB2312) SCP_csiso58gb231280 = 936 ' Chinese Simplified (GB2312) SCP_gb_2312_80 = 936 ' Chinese Simplified (GB2312) SCP_gb2312 = 936 ' Chinese Simplified (GB2312) SCP_hz_gb_2312 = 936 ' Chinese Simplified (HZ) SCP_iso_ir_58 = 936 ' Chinese Simplified (GB2312) SCP_cseuckr = 949 ' Korean SCP_csksc56011987 = 949 ' Korean SCP_euc_kr = 949 ' Korean SCP_iso_ir_149 = 949 ' Korean SCP_korean = 949 ' 韓文 SCP_ks_c_5601 = 949 ' Korean SCP_ks_c_5601_1987 = 949 ' Korean SCP_ks_c_5601_1989 = 949 ' Korean SCP_ksc_5601 = 949 ' Korean SCP_ksc5601 = 949 ' Korean SCP_big5 = 950 ' 繁體中文 (BIG5) SCP_csbig5 = 950 ' 繁體中文 (BIG5) SCP_x_x_big5 = 950 ' 繁體中文 (BIG5) SCP_CP_Default_Windows = 1200 ' Windows SCP_CP_Little_Endian_Unicode = 1200 ' Windows SCP_CP_UTF_16LE = 1200 ' Windows SCP_CP_Big_Endian_Unicode = 1201 ' SCP_CP_UTF_16BE = 1201 ' SCP_windows_1250 = 1250 ' Central European (Windows) SCP_x_cp1250 = 1250 ' Central European (Windows) SCP_windows_1251 = 1251 ' Cyrillic (Windows) SCP_x_cp1251 = 1251 ' Cyrillic (Windows) SCP_ansi_x3_4_1968 = 1252 ' Western SCP_ansi_x3_4_1986 = 1252 ' Western SCP_ascii = 1252 ' Western SCP_cp367 = 1252 ' Western SCP_cp819 = 1252 ' Western SCP_csascii = 1252 ' Western SCP_ibm367 = 1252 ' Western SCP_ibm819 = 1252 ' Western SCP_iso_646_irv_1991 = 1252 ' Western SCP_iso_8859_1 = 1252 ' Western SCP_iso_8859_1_1987 = 1252 ' Western SCP_iso_ir_100 = 1252 ' Western SCP_iso_ir_6 = 1252 ' Western SCP_iso646_us = 1252 ' Western SCP_iso8859_1 = 1252 ' Western SCP_latin1 = 1252 ' Western SCP_us = 1252 ' Western SCP_us_ascii = 1252 ' Western SCP_windows_1252 = 1252 ' Western SCP_windows_1253 = 1253 ' Greek (Windows) SCP_windows_1254 = 1254 ' Turkish (Windows) SCP_csisolatinhebrew = 1255 ' Hebrew (ISO_Visual) SCP_hebrew = 1255 ' Hebrew SCP_iso_8859_8 = 1255 ' Hebrew (ISO_Visual) SCP_iso_8859_8_1988 = 1255 ' Hebrew (ISO_Visual) SCP_iso_ir_138 = 1255 ' Hebrew (ISO_Visual) SCP_windows_1255 = 1255 ' Hebrew SCP_windows_1256 = 1256 ' Arabic SCP_windows_1257 = 1257 ' Baltic (Windows) SCP_windows_1258 = 1258 ' Vietnamese SCP_CP_ASCII = 20127 ' SCP_cskoi8r = 20866 ' Cyrillic (KOI8_R) SCP_koi8_r = 20866 ' Cyrillic (KOI8_R) SCP_csisolatin2 = 28592 ' Central European (ISO) SCP_iso_8859_2 = 28592 ' Central European (ISO) SCP_iso_8859_2_1987 = 28592 ' Central European (ISO) SCP_iso_ir_101 = 28592 ' Central European (ISO) SCP_iso8859_2 = 28592 ' Central European (ISO) SCP_l2 = 28592 ' Central European (ISO) SCP_latin2 = 28592 ' Central European (ISO) SCP_csiso2022kr = 50225 ' Korean (ISO) SCP_iso_2022_kr = 50225 ' Korean (ISO) SCP_CP_GB18030 = 54936 ' 簡體中文 SCP_CP_UTF7 = 65000 ' Unicode (UTF_7) SCP_CP_UTF8 = 65001 ' Unicode (UTF_8) End Enum Public Enum enuChineseFlags CF_Default = 0 CF_Little = 0 CF_Big = 1 CF_Number = 2 CF_Unit = 4 CF_Unit_Little = CF_Unit Or CF_Little CF_Unit_Big = CF_Unit Or CF_Big CF_Number_Little = CF_Number Or CF_Little CF_Number_Big = CF_Number Or CF_Big CF_Add_Comma = 65536 End Enum Private Enum enuChineseStringIndex CSI_Default = 0 CSI_Unit_Little = 1 CSI_Unit_Big = 2 CSI_Number_Little = 3 CSI_Number_Big = 4 End Enum Public Function GetChineseDateTime(ByVal sDateTime As String) As Date Dim lbc, ubc, sLoc, eLoc, nLen, iUnit As Integer Dim addHour As Double Dim m_strYear As String() = Split("秒,分,時,日,月,年", ",") lbc = LBound(m_strYear) ubc = UBound(m_strYear) sDateTime = Replace(sDateTime, "民國", "") If InStr(sDateTime, "下午") Then addHour += 12 Else addHour = 0 End If sDateTime = Replace(sDateTime, "下午", "") Dim arrDateTime(ubc) As Double sLoc = 1 nLen = Len(sDateTime) For iUnit = ubc To lbc Step -1 eLoc = InStr(sLoc, sDateTime, m_strYear(iUnit)) If eLoc > 0 Then arrDateTime(iUnit) = GetChineseNumber(Mid(sDateTime, sLoc, eLoc - sLoc)) sLoc = eLoc + 1 End If If sLoc > nLen Then Exit For End If Next Return DateSerial(arrDateTime(5) + 1911, arrDateTime(4), arrDateTime(3)) + TimeSerial(arrDateTime(2) + addHour, arrDateTime(1), arrDateTime(0)) End Function Private Function SetChineseNumberInit() As Object Dim m_strUnit As String() = Split("個,萬,億,兆,京,垓,杼,穰,溝,澗,正,載,極,恆河沙,阿僧祇,那由他,不可思議,無量,大數", ",") ' 10 ^ 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72 Dim m_strUnitLittle As String() = Split("個,十,百,千", ",") Dim m_strUnitBig As String() = Split("個,拾,佰,仟", ",") Dim m_strNumLittle As String() = Split("○,一,二,三,四,五,六,七,八,九", ",") Dim m_strNumBig As String() = Split("零,壹,貳,參,肆,伍,陸,柒,捌,玖", ",") SetChineseNumberInit = MyArray(m_strUnit, m_strUnitLittle, m_strUnitBig, m_strNumLittle, m_strNumBig) End Function Public Function SetChineseNumber(ByVal vNumber As Double, Optional ByVal lFlags As enuChineseFlags = enuChineseFlags.CF_Default) As String Dim sNumber As String Dim arrRep As Object Dim ibc, ubc As Integer Dim m_ChineseNumber As Object = SetChineseNumberInit() sNumber = vNumber.ToString If lFlags And enuChineseFlags.CF_Add_Comma Then Dim sFmt As String = "#,##0" If InStr(sNumber, ".") > 0 Then sFmt &= "." & New String("0", Len(sNumber) - InStr(sNumber, ".")) End If sNumber = vNumber.ToString(sFmt) End If If lFlags And enuChineseFlags.CF_Big Then arrRep = m_ChineseNumber(enuChineseStringIndex.CSI_Number_Big) Else arrRep = m_ChineseNumber(enuChineseStringIndex.CSI_Number_Little) End If ubc = UBound(arrRep) For ibc = 0 To ubc sNumber = Replace(sNumber, CStr(ibc), arrRep(ibc)) Next sNumber = Replace(sNumber, ",", "、") sNumber = Replace(sNumber, ".", "•") Return sNumber End Function Public Function GetChineseNumber(ByVal sNumber As String, Optional ByVal lFlags As enuChineseFlags = enuChineseFlags.CF_Default) As Double Dim i, lbc, ubc, iUnit, nPower, nNextFlags, sLoc, eLoc, nLen As Integer Dim m_CN, m_RP As Object Dim tValue, tConf As Double Dim m_ChineseNumber As Object = SetChineseNumberInit() If lFlags = enuChineseFlags.CF_Default Then sNumber = Replace(sNumber, "廿", "二十") sNumber = Replace(sNumber, "卅", "三十") sNumber = Replace(sNumber, "、", "") For i = 1 To 3 Step 2 m_CN = m_ChineseNumber(i) lbc = LBound(m_CN) ubc = UBound(m_CN) m_RP = m_ChineseNumber(i + 1) For iUnit = lbc To ubc sNumber = Replace(sNumber, m_RP(iUnit), m_CN(iUnit)) Next Next End If tValue = 0 Select Case lFlags Case enuChineseFlags.CF_Default nPower = 4 nNextFlags = 1 Case enuChineseFlags.CF_Unit_Little, enuChineseFlags.CF_Unit_Big nPower = 1 nNextFlags = 3 Case enuChineseFlags.CF_Number_Little, enuChineseFlags.CF_Number_Big End Select m_CN = m_ChineseNumber(lFlags) lbc = LBound(m_CN) ubc = UBound(m_CN) sLoc = 1 nLen = Len(sNumber) Select Case lFlags Case enuChineseFlags.CF_Default, enuChineseFlags.CF_Unit_Little, enuChineseFlags.CF_Unit_Big For iUnit = ubc To lbc Step -1 eLoc = InStr(sLoc, sNumber, m_CN(iUnit)) If eLoc > 0 Then If eLoc = sLoc Then tConf = 1 Else tConf = GetChineseNumber(Mid(sNumber, sLoc, eLoc - sLoc), nNextFlags) End If On Error Resume Next tValue += tConf * CDec(10 ^ (nPower * iUnit)) If Err.Number = 6 Then Err.Clear() tValue += tConf * CDbl(10 ^ (nPower * iUnit)) End If On Error GoTo 0 sLoc = eLoc + 1 ElseIf iUnit = lbc Then tValue += GetChineseNumber(Mid(sNumber, sLoc), nNextFlags) End If If sLoc > nLen Then Exit For End If Next Case enuChineseFlags.CF_Number_Little, enuChineseFlags.CF_Number_Big For iUnit = lbc To ubc sNumber = Replace(sNumber, m_CN(iUnit), CStr(iUnit)) Next tValue += Val(sNumber) End Select Return tValue End Function Public Function GetDataNumericFormat(ByVal vData, ByVal sFormat) As String Dim sLoc, eLoc, hLoc, ibf, lbf, ubf As Integer Dim midFormat, fmtData As String Dim fmt As Object Dim sOutput As String = "" Dim nStart As Integer = 1 Do sLoc = InStr(nStart, sFormat, "{") If sLoc > 0 Then eLoc = InStr(sLoc + 1, sFormat, "}") If eLoc > 0 Then midFormat = Mid(sFormat, sLoc + 1, eLoc - sLoc - 1) hLoc = InStr(LCase(midFormat), "&h") If hLoc > 0 Then fmt = Split(midFormat, ";") lbf = LBound(fmt) ubf = UBound(fmt) For ibf = lbf To ubf hLoc = InStr(LCase(fmt(ibf)), "&h") If hLoc > 0 Then fmtData &= Mid(fmt(ibf), 1, hLoc - 1) & Hex(CLng(myFormatNumeric(vData, Mid(fmt(ibf), hLoc + 2)))) Else fmtData &= myFormatNumeric(vData, fmt(ibf)) End If Next Else fmtData = myFormatNumeric(vData, midFormat) End If sOutput &= Mid(sFormat, nStart, sLoc - nStart) & fmtData nStart = eLoc + 1 Else sOutput &= Mid(sFormat, nStart, sLoc - nStart) & "{" nStart = sLoc + 1 End If Else sOutput &= Mid(sFormat, nStart) End If Loop Until sLoc = 0 GetDataNumericFormat = sOutput End Function Public Function myFormatNumeric(ByVal vData As Double, ByVal strFormat As String) As String If IsNothing(vData) Then Return Nothing ElseIf strFormat = "" Then Return CStr(vData) Else Dim sDot, sCommon As String() Dim ubd, ubc, nLen, nLoc, ic, nDot As Integer Dim sNumeric As Object Dim sAddFirst As String sDot = Split(strFormat, ".") ' 偵測小數點 ubd = UBound(sDot) If ubd > 0 Then sNumeric = CStr(Math.Round(vData, Len(sDot(1)))) If InStr(sNumeric, ".") = 0 Then sNumeric &= "." End If Else sNumeric = CStr(Math.Round(vData, 0)) End If sNumeric = Split(sNumeric, ".") ' 偵測小數點 sCommon = Split(sDot(0), ",") ' 偵測逗號 ubc = UBound(sCommon) If ubc > 0 Then nLen = Len(sNumeric(0)) nLoc = ((nLen - 1) Mod 3) + 1 For ic = 1 To (nLen - 1) \ 3 sNumeric(0) = Left(sNumeric(0), nLoc) & "," & Mid(sNumeric(0), nLoc + 1) nLoc += 4 Next End If nLen = Len(sNumeric(0)) nDot = Len(sDot(0)) If nDot > nLen Then sAddFirst = Left(sDot(0), nDot - nLen) sAddFirst = Replace(sAddFirst, "#", "") sAddFirst = Replace(sAddFirst, ",", "") sNumeric(0) = sAddFirst & sNumeric(0) End If If ubd > 0 Then nLen = Len(sNumeric(1)) nDot = Len(sDot(1)) sNumeric(1) &= Mid(sDot(1), nLen + 1, nDot - nLen) sNumeric(1) = Replace(sNumeric(1), "#", "") End If Return Join(sNumeric, ".") End If End Function Public Function GetDataDateFormat(ByVal vDate As Date, ByVal sFormat As String) As String Dim sLoc, eLoc, hLoc, ibf, lbf, ubf As Integer Dim midFormat, fmtDate As String Dim fmt As Object Dim sOutput As String = "" Dim nStart As Integer = 1 Do sLoc = InStr(nStart, sFormat, "[") If sLoc > 0 Then eLoc = InStr(sLoc + 1, sFormat, "]") If eLoc > 0 Then midFormat = Mid(sFormat, sLoc + 1, eLoc - sLoc - 1) hLoc = InStr(LCase(midFormat), "&h") If hLoc > 0 Then fmt = Split(midFormat, ";") lbf = LBound(fmt) ubf = UBound(fmt) For ibf = lbf To ubf hLoc = InStr(LCase(fmt(ibf)), "&h") If hLoc > 0 Then 'fmtDate &= Mid(fmt(ibf), 1, hLoc - 1) & Hex(CLng(Format(vDate, Mid(fmt(ibf), hLoc + 2)))) fmtDate &= Mid(fmt(ibf), 1, hLoc - 1) & Hex(CLng(vDate.ToString(Mid(fmt(ibf), hLoc + 2)))) Else fmtDate &= Format(vDate, fmt(ibf)) End If Next Else 'fmtDate = Format(vDate, midFormat) fmtDate = vDate.ToString(midFormat) End If sOutput &= Mid(sFormat, nStart, sLoc - nStart) & fmtDate nStart = eLoc + 1 Else sOutput &= Mid(sFormat, nStart, sLoc - nStart) & "[" nStart = sLoc + 1 End If Else sOutput &= Mid(sFormat, nStart) End If Loop Until sLoc = 0 Return sOutput End Function Public Function GetContinueString(Byval strSource As String, Byval strFind As String) As String Dim sLoc As Integer = InStr(strSource, strFind) If sLoc > 0 Then Dim ibl, nLen As Integer Dim sReturn As String nLen = Len(strFind) If sLoc + nLen > Len(strSource) Then sReturn = Mid(strSource, sLoc) Else For ibl = sLoc + nLen To Len(strSource) Step nLen If Mid(strSource, ibl, nLen) <> strFind Then sReturn = Mid(strSource, sLoc, ibl - sLoc) Exit For ElseIf ibl + nLen >= Len(strSource) Then sReturn = Mid(strSource, sLoc) End If Next End If Return sReturn Else Return "" End If End Function Public Function GetSubStringFromFind(Byval strSource As String, Byval strFormat As String, Byval strFind As String) As String Dim sLoc, nLen As Integer sLoc = InStr(strFormat, strFind) nLen = Len(strFind) If sLoc > 0 Then Return Mid(strSource, sLoc, nLen) Else Return "" End If End Function Public Function GetDateFromString(Byval strSource As String, Byval strFormat As String) As Date Dim nYear, nMonth, nDay, nHour, nMinute, nSecond As Integer Dim sLoc, nLen As Integer Dim strItem As String ' nYear strItem = GetContinueString(LCase(strFormat), "e") If strItem <> "" Then nYear = CInt(GetSubStringFromFind(strSource, LCase(strFormat), strItem)) + 1911 Else strItem = GetContinueString(LCase(strFormat), "y") If strItem <> "" Then nYear = CInt(GetSubStringFromFind(strSource, LCase(strFormat), strItem)) If Len(strItem) = 2 Then nYear += 2000 End If End If End If ' nMonth strItem = GetContinueString(strFormat, "M") If strItem <> "" Then nMonth = CInt(GetSubStringFromFind(strSource, strFormat, strItem)) End If ' nDay strItem = GetContinueString(LCase(strFormat), "d") If strItem <> "" Then nDay = CInt(GetSubStringFromFind(strSource, LCase(strFormat), strItem)) End If ' nHour strItem = GetContinueString(LCase(strFormat), "h") If strItem <> "" Then nHour = CInt(GetSubStringFromFind(strSource, LCase(strFormat), strItem)) End If ' nMinute strItem = GetContinueString(LCase(strFormat), "n") If strItem <> "" Then nMinute = CInt(GetSubStringFromFind(strSource, LCase(strFormat), strItem)) Else strItem = GetContinueString(strFormat, "m") If strItem <> "" Then nMinute = CInt(GetSubStringFromFind(strSource, strFormat, strItem)) End If End If ' nSecond strItem = GetContinueString(LCase(strFormat), "s") If strItem <> "" Then nSecond = CInt(GetSubStringFromFind(strSource, LCase(strFormat), strItem)) End If Return New DateTime(nYear, nMonth, nDay, nHour, nMinute, nSecond) End Function Public Function InstrString(ByVal objSource As Object, Optional ByVal strDelimiter As Object = " ", Optional ByVal nCount As Object = Nothing, Optional ByVal bContinue As Object = False, Optional ByVal ChangeVariant As Object = False) As Object Dim ibs As Integer If IsArray(objSource) Then Dim arrReturn(UBound(objSource)) As Object Dim aCount, aContinue, aVariant As Object For ibs = 0 To UBound(objSource) If IsArray(nCount) Then aCount = nCount(ibs) Else aCount = nCount If IsArray(bContinue) Then aContinue = bContinue(ibs) Else aContinue = bContinue If IsArray(ChangeVariant) Then aVariant = ChangeVariant(ibs) Else aVariant = ChangeVariant arrReturn(ibs) = InstrString(objSource(ibs), strDelimiter, aCount, aContinue, aVariant) Next Return arrReturn Else Dim arrDelimiter(), arrReturn() As Object Dim nLen, ibr, ubr As Integer Dim strReturn As String() Dim strSource As String = CStr(objSource) If IsArray(strDelimiter) Then ubr = UBound(strDelimiter) ReDim arrDelimiter(ubr) For ibs = 0 To ubr If IsArray(strDelimiter(ibs)) Then arrDelimiter(ibs) = strDelimiter(ibs)(0) For ibr = 1 To UBound(strDelimiter(ibs)) strSource = Replace(strSource, strDelimiter(ibs)(ibr), arrDelimiter(ibs)) Next Do nLen = Len(strSource) strSource = Replace(strSource, arrDelimiter(ibs) & arrDelimiter(ibs), arrDelimiter(ibs)) Loop Until nLen = Len(strSource) Else arrDelimiter(ibs) = strDelimiter(ibs) End If Next Else arrDelimiter = MyArray(strDelimiter) End If If bContinue Then For ibs = 0 To UBound(arrDelimiter) Do nLen = Len(strSource) strSource = Replace(strSource, arrDelimiter(ibs) & arrDelimiter(ibs), arrDelimiter(ibs)) Loop Until nLen = Len(strSource) Next End If For ibs = 1 To UBound(arrDelimiter) strSource = Replace(strSource, arrDelimiter(ibs), arrDelimiter(0)) Next strReturn = Split(strSource, arrDelimiter(0)) ubr = UBound(strReturn) ReDim arrReturn(ubr) If ChangeVariant Then For ibs = 0 To ubr arrReturn(ibs) = CVariant(strReturn(ibs)) Next Else For ibs = 0 To ubr arrReturn(ibs) = strReturn(ibs) Next End If If IsNothing(nCount) Then Return arrReturn Else nCount = CInt(nCount) If nCount >= 0 Then Return arrReturn(nCount) Else nCount = -nCount ReDim Preserve arrReturn(nCount) Return arrReturn End If End If End If End Function Public Function MyLen(ByVal vString As String) As Integer Dim arrBytes As Byte() arrBytes = StringToBytes(vString) arrBytes = BytesChangeCodePages(arrBytes, enuStandardCodePages.SCP_CP_Default_Windows, enuStandardCodePages.SCP_big5) Return UBound(arrBytes) + 1 End Function Public Function MyMid(ByVal vString As String, ByVal iStart As Integer, Optional ByVal iLength As Integer = 0) As String Dim srcBytes, dstBytes As Byte() Dim ubb As Integer srcBytes = StringToBytes(vString) srcBytes = BytesChangeCodePages(srcBytes, enuStandardCodePages.SCP_CP_Default_Windows, enuStandardCodePages.SCP_big5) ubb = UBound(srcBytes) If iLength = 0 Then iLength = ubb + 1 - iStart + 1 ElseIf (iStart + iLength - 1) >= (ubb + 1) Then iLength = ubb + 1 - iStart + 1 End If ReDim dstBytes(iLength - 1) Array.Copy(srcBytes, iStart - 1, dstBytes, 0, iLength) srcBytes = BytesChangeCodePages(dstBytes, enuStandardCodePages.SCP_big5, enuStandardCodePages.SCP_CP_Default_Windows) Return BytesToString(srcBytes) End Function Public Function CVariant(ByVal strSource As Object) As Object If IsNothing(strSource) Or LCase(Trim(strSource)) = "nothing" Then CVariant = Nothing ElseIf IsDBNull(strSource) Or LCase(Trim(strSource)) = "null" Then CVariant = DBNull.Value ElseIf IsNumeric(strSource) Then CVariant = CDbl(strSource) ElseIf IsDate(strSource) Then CVariant = CDate(strSource) ElseIf IsBoolean(strSource) Then CVariant = CBool(strSource) Else CVariant = strSource End If End Function Public Function IsBoolean(ByVal vBool) As Boolean Dim tBool As Boolean IsBoolean = True Try tBool = CBool(vBool) Catch ex As Exception IsBoolean = False End Try End Function Public Function StringChangeCodePages(ByVal srcString As String, Optional ByVal srcCodePage As enuStandardCodePages = enuStandardCodePages.SCP_big5, Optional ByVal dstCodePage As enuStandardCodePages = enuStandardCodePages.SCP_CP_Default_Windows) As String Dim arrBytes As Byte() arrBytes = StringToBytes(srcString, srcCodePage) arrBytes = BytesChangeCodePages(arrBytes, srcCodePage, dstCodePage) 'Return BytesToString(arrBytes, dstCodePage) Return BytesToString(arrBytes, enuStandardCodePages.SCP_CP_Default_Windows) End Function Public Function BytesChangeCodePages(ByVal arrBytes As Byte(), Optional ByVal srcCodePage As enuStandardCodePages = enuStandardCodePages.SCP_big5, Optional ByVal dstCodePage As enuStandardCodePages = enuStandardCodePages.SCP_CP_Default_Windows) As Byte() Dim srcEncoding As Encoding = Encoding.GetEncoding(srcCodePage) Dim dstEncoding As Encoding = Encoding.GetEncoding(dstCodePage) Return Encoding.Convert(srcEncoding, dstEncoding, arrBytes) End Function Public Function Big5ToUnicode(ByVal arrBytes As Byte()) As Byte() ' 繁體中文 (Big5) 字碼頁為 950 'Dim Big5Encoding As Encoding = Encoding.GetEncoding(950) 'Return Encoding.Convert(Big5Encoding, Encoding.Unicode, arrBytes) Return BytesChangeCodePages(arrBytes) End Function Public Function BytesToString(ByVal arrBytes As Byte(), Optional ByVal dstCodePage As enuStandardCodePages = enuStandardCodePages.SCP_CP_Default_Windows) As String Dim uniDecoder As Encoding = Encoding.GetEncoding(dstCodePage) Return uniDecoder.GetString(arrBytes) End Function Public Function StringToBytes(ByVal srcString As String, Optional ByVal dstCodePage As enuStandardCodePages = enuStandardCodePages.SCP_CP_Default_Windows) As Byte() Dim uniDecoder As Encoding = Encoding.GetEncoding(dstCodePage) Return uniDecoder.GetBytes(srcString) End Function Public Function MyArray(ByVal ParamArray arrVar()) Return arrVar End Function < / s c r i p t>