Reading gibberish filename (FTP/FSO) - vbscript

Looking at my server, i see filenames, that theur characters have been messed up.
Example: ôøùú-ô÷åãé-1.mp3
should should be Hebrew letters.
While the files can be read in a browser and FTP, they cannot be read always - for example, in an online audio player, or VBScript FSO (File system object)
is there something that can be done to change the charset or something, so that i can read and then rename these files?
Thanks!

solved, using this link: http://pastebin.com/yXRWDggY
function convertChar(letter)
lat = array("à","á","â","ã","ä","å","æ","ç","è","é","ê","ë","ì","í","î","ï","ð","ñ","ò","ó","ô","õ","ö","÷","ø","ù","ú", " " )
heb = array("א","ב","ג","ד","ה","ו","ז","ח","ט","י","ך","כ","ל","ם","מ","ן","נ","ס","ע","ף","פ","ץ","צ","ק","ר","ש","ת", " ")
inarray = false
for ii = 0 to ubound(heb)
if letter = heb(ii) then
convertChar = lat(ii)
inarray = true
exit for
end if
next
if inarray = false then convertChar = letter
end function

Related

Remove the desired content from a text

I would like to get a working code to simply remove from a text line a specific part that always begins with "(" and finish with ")".
Sample text : Hello, how are you (it is a question)
I want to remove this part: "(it is a question)" to only keep this message "Hello, how are you"
Lost...
Thanks
One way using Regular Expressions;
input = "Hello, how are you (it is a question)"
dim re: set re = new regexp
with re
.pattern = "\(.*\)\s?" '//anything between () and if present 1 following whitespace
.global = true
input = re.Replace(input, "")
end with
msgbox input
If the part to be removed is always at the end of the string, string operations would work as well:
msg = "Hello, how are you (it is a question)"
pos = InStr(msg, "(")
If pos > 0 Then WScript.Echo Trim(Left(msg, pos-1))
If the sentence always ends with the ( ) section, use the split function:
line = "Hello, how are you (it is a question)"
splitter = split(line,"(") 'splitting the line into 2 sections, using ( as the divider
endStr = splitter(0) 'first section is index 0
MsgBox endStr 'Hello, how are you
If it is in the middle of the sentence, use the split function twice:
line = "Hello, how are you (it is a question) and further on"
splitter = split(line,"(")
strFirst = splitter(0) 'Hello, how are you
splitter1 = split(line,")")
strSecond = splitter1(UBound(Splitter1)) 'and further on
MsgBox strFirst & strSecond 'Hello, how are you and further on
If there is only one instance of "( )" then you could use a '1' in place of the UBound.
Multiple instances I would split the sentence and then break down each section containing the "( )" and concatenate the final sentence.

Check if string "starts with" another string

I want to check if an address starts with http://www.youtube.com.
If I have something like this
if rs("mainVideoName")="http://www.youtube.com*" then
This doesn't work, so how can I do it?
Try this:
Function UrlStartsWith(string1, string2)
UrlStartsWith = InStr(1, string1, string2, 1) = 1
End Function
If UrlStartsWith(rs("mainVideoName"), "http://www.youtube.com") Then
End If
Starts with is tested by using IntStr and ensuring that it returns 1 as the starting position that the search string is found. Since you are testing a URL the code above uses a TextCompare to make insensitive to case.
You can use the InStr() function for this:
Dim positionOfMatchedString
positionOfMatchedString= InStr(rs("mainVideoName"),"http://www.youtube.com")
If positionOfMatchedString > 0 Then
// Do your stuff here
End If
As Anthony points out, this tells you that string2 is contained in string1. You could write it as:
If positionOfMatchedString = 1 Then
to check for it beginning with.
How about...
Dim s: s = "http://www.youtube.com"
Dim l: l = Len(s)
If Left(rs("mainVideoName"), l) = s Then
' String begins with URL part '
End If

VB6 - converting string to double using specific culture?

I am a long time C# developer and have had to look at some VB6 code lately. After some digging, we found out that, somewhere, somehow, we are storing a number as a string. Now we are reading it back and our code is not handling culture differences very well. Here is an example:
Dim text as String
Dim myVal as Double
Set text = "1,123456"
'This sets the value of myVal to 1123456 on our system - incorrect
myVal = text
Set text = "1.123456"
'This sets the value of myVal to 1.123456 on our system - correct
myVal = text
Keeping in mind that this is VB6 and NOT VB.NET, are there any built-in methods, functions, whatever, that can convert a string to a double using a particular culture?
Or at the very least, hinting to the conversion that we may be dealing with a different format?
We are still digging how the value gets written and see if we can reverse engineer the process to give us a consistent result. However, our customer(s) already has(have) data in one format or the other (or both, we are checking...), so a proper conversion algorithm or implementation would be a better answer at this point.
I've used this quick and dirty function in the past to get a double from a text. Here in Argentina, people sometimes use the point and sometimes the comma to separate decimal values, so this function is ready to accept both formats. If only one punctuation is present, it's assumed that it's the decimal separator.
function ConvertDBL( texto )
dim retval, SepDecimal, SepMiles
If texto = "" then texto = "0"
retval = replace(trim(texto), " ", "")
If cdbl("3,24") = 324 then
SepDecimal = "."
SepMiles = ","
else
SepDecimal = ","
SepMiles = "."
end if
If InStr( Retval, SepDecimal ) > 0 then
If InStr( Retval, SepMiles ) > 0 then
If InStr( Retval, SepDecimal ) > InStr( Retval, SepMiles ) then
Retval = replace( Retval, SepMiles, "" )
else
Retval = replace( Retval, SepDecimal, "" )
Retval = replace( Retval, SepMiles, SepDecimal )
end if
end if
else
Retval = replace( Retval, SepMiles, SepDecimal )
end if
ConvertDbl = cdbl( retval )
end function
You cannot choose an arbitrary culture by passing a culture object like you can in .Net. You can choose:
Functions which always use the current regional settings. CStr, Format, CDbl etc. Implicit conversions (like the ones in your question) also use the current regional settings.
Functions which always use USA regional settings (similar to the .Net invariant culture). Str, Val
Usually the current regional settings are taken from Control Panel. There are rumours that you can call SetThreadLocale to change the regional settings from code at runtime - never tried it myself.
In Visual Basic tested works very fast and efficient.
Step 1: Conversion from a string to a value representation.
Step 2: Conversion from a value representation to a double integer value.
Dim Str as String
Dim mValue as double
str = "100,10"
mValue = CDbl(Val(str))

VB6: Is there a standard library (parser) to strip HTML tags from content? [duplicate]

How to strip ALL HTML tags using MSHTML Parser in VB6?
This is adapted from Code over at CodeGuru. Many Many thanks to the original author:
http://www.codeguru.com/vb/vb_internet/html/article.php/c4815
Check the original source if you need to download your HTML from the web. E.g.:
Set objDocument = objMSHTML.createDocumentFromUrl("http://google.com", vbNullString)
I don't need to download the HTML stub from the web - I already had my stub in memory. So the original source didn't quite apply to me. My main goal is just to have a qualified DOM Parser strip the HTML from the User generated content for me. Some would say, "Why not just use some RegEx to strip the HTML?" Good luck with that!
Add a reference to: Microsoft HTML Object Library
This is the same HTML Parser that runs Internet Explorer (IE) - Let the heckling begin. Well, Heckle away...
Here's the code I used:
Dim objDocument As MSHTML.HTMLDocument
Set objDocument = New MSHTML.HTMLDocument
'NOTE: txtSource is an instance of a simple TextBox object
objDocument.body.innerHTML = "<p>Hello World!</p> <p>Hello Jason!</p> <br/>Hello Bob!"
txtSource.Text = objDocument.body.innerText
The resulting text in txtSource.Text is my User's Content stripped of all HTML. Clean and maintainable - No Cthulhu Way for me.
One way:
Function strip(html As String) As String
With CreateObject("htmlfile")
.Open
.write html
.Close
strip = .body.outerText
End With
End Function
For
?strip("<strong>hello <i>wor<u>ld</u>!</strong><foo> 1234")
hello world! 1234
Public Function ParseHtml(ByVal str As String) As String
Dim Ret As String, TagOpenend As Boolean, TagClosed As Boolean
Dim n As Long, sChar As String
For n = 1 To Len(str)
sChar = Mid(str, n, 1)
Select Case sChar
Case "<"
TagOpenend = True
Case ">"
TagClosed = True
TagOpenend = False
Case Else
If TagOpenend = False Then
Ret = Ret & sChar
End If
End Select
Next
ParseHtml = Ret
End Function
This is a simple function i mafe for my own use.
use Debug window
?ParseHtml( "< div >test< /div >" )
test
I hope this will help without using external libraries

How to strip ALL HTML tags using MSHTML Parser in VB6?

How to strip ALL HTML tags using MSHTML Parser in VB6?
This is adapted from Code over at CodeGuru. Many Many thanks to the original author:
http://www.codeguru.com/vb/vb_internet/html/article.php/c4815
Check the original source if you need to download your HTML from the web. E.g.:
Set objDocument = objMSHTML.createDocumentFromUrl("http://google.com", vbNullString)
I don't need to download the HTML stub from the web - I already had my stub in memory. So the original source didn't quite apply to me. My main goal is just to have a qualified DOM Parser strip the HTML from the User generated content for me. Some would say, "Why not just use some RegEx to strip the HTML?" Good luck with that!
Add a reference to: Microsoft HTML Object Library
This is the same HTML Parser that runs Internet Explorer (IE) - Let the heckling begin. Well, Heckle away...
Here's the code I used:
Dim objDocument As MSHTML.HTMLDocument
Set objDocument = New MSHTML.HTMLDocument
'NOTE: txtSource is an instance of a simple TextBox object
objDocument.body.innerHTML = "<p>Hello World!</p> <p>Hello Jason!</p> <br/>Hello Bob!"
txtSource.Text = objDocument.body.innerText
The resulting text in txtSource.Text is my User's Content stripped of all HTML. Clean and maintainable - No Cthulhu Way for me.
One way:
Function strip(html As String) As String
With CreateObject("htmlfile")
.Open
.write html
.Close
strip = .body.outerText
End With
End Function
For
?strip("<strong>hello <i>wor<u>ld</u>!</strong><foo> 1234")
hello world! 1234
Public Function ParseHtml(ByVal str As String) As String
Dim Ret As String, TagOpenend As Boolean, TagClosed As Boolean
Dim n As Long, sChar As String
For n = 1 To Len(str)
sChar = Mid(str, n, 1)
Select Case sChar
Case "<"
TagOpenend = True
Case ">"
TagClosed = True
TagOpenend = False
Case Else
If TagOpenend = False Then
Ret = Ret & sChar
End If
End Select
Next
ParseHtml = Ret
End Function
This is a simple function i mafe for my own use.
use Debug window
?ParseHtml( "< div >test< /div >" )
test
I hope this will help without using external libraries

Resources