Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Instr function can't find a character 3

Status
Not open for further replies.

sglab

Technical User
Jul 29, 2003
104
US
Hello everyone,
I have this weird - at least to me - problem. I have files' names that contain "/" characters as in [blue]"10?13?2010 RER Weekly eNewsletter [72A6][122096].eml.msg.htm"[/blue]. The task is to to rename files by replacing "?" for "_". When I go character-by-charater in the file name, using Mid function as in Mid(fName,i,1) then "?" is recognized as character 47. But when I use Instr(1, fName, chr(47)) it returns 0. I hope you can see the difference between character "?" and "/" . How come both have ASC code of 47. What is that character "?" ?
Thank you in advance.
 


This is probably from an "extended characterset"

If you open the Character Map and choose Advanced view.

Group By Unicode Subrange

In the Group By window select General Punctuation and then select the forward slash

Then in the Group By window select Mathematical Operators and then select the forward slash

Notice the difference in these characters (47 & 63 which happens to be the QUESTION MARK) Its all about character set mapping.


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Based on your own findings and SkipVought's explanation, it would seem that mid and instr use different character sets. If you can traverse a string char by char and replace chr(47) with chr(95) (underscore), what problem is there? :)

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Hello Skip,

Thank you for your reply.
I did go to Character Map and saw the difference between actually 3 instances of forward slash: 2F and 2044 in General Punctuation and 2215 in Mathematical Operators.
Question still remains: why Instr can't find either of them while Mid function has no problem?
See, I can go character-by-character in the file name and when Mid finds chr(47) then replace it for "_" using again Mid function - Replace doesn't work just like Instr doesn't - and this approach does work. But it's tens of thousands of files and I'm concerned about it taking too much time.

Thank you.
 
Perhaps a regex solution would help here:
Code:
'[URL unfurl="true"]http://msdn.microsoft.com/en-us/library/ms974570.aspx[/URL]
'[URL unfurl="true"]http://msdn.microsoft.com/en-us/library/yab2dx62.aspx[/URL]
'[URL unfurl="true"]http://www.regular-expressions.info/index.html[/URL]

strIn = "10/13/2010 RER Weekly eNewsletter [72A6][122096].eml.msg.htm"
strOut = CleanString(strIn)
'do something with the new string
wscript.echo("Input: " & strIn & vbcrlf & "Output: " & strOut)

Function CleanString(strInput)

'create regular expression object
set re = new regexp
'set the pattern to match: characters that look like forward slashes (solidus [U+002F], fraction slash [U+2044], and division slash [U+2215])
re.Pattern = "(\u002F|\u2044|\u2215)"
re.IgnoreCase = True
'match all instances found
re.Global = True

CleanString = re.Replace(strInput, "_")

'free memory
set re = nothing

End Function
 
Hello jges,

thank you for the idea. I'll definitely try this approach.

Best regards.
 
Hello jges,

I tried your approach and it did work just perfect.
Thank you so much and good luck.

I also wanted to thank everyone for their input as they showed me different ways of looking at the data I'm working with.

Best regards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top