hello all
i am writing a database app for my company, the problem i have now is that when i pull the file path from the database it looks like this c:text.txt when i need it to look like this c:\text.txt,, i know the \ is the escape character in mysql, when im pulling the file path from the db i put it into a label first then use that to execute the file, is there anyway i can search that string of text for say the : then add a \ behind it when it finds it so the file path will be correct, i was thinking something like an if statement would work, but i do not have any idea on how to set that up, so please just a little advice!!! please!
thanks tons....
5 1201
hi
use inStr() function
usage:
if instr(1,"C:\Tex.text",":") > 0 then
': found
endif
regards
manpreet singh dhillon hoshiarpur
so i tried that but how do i add in a "\" behind the ":"... the add in will be in the same place everytime if that helps...i really new to vb and nothing on google really explains an insert method....
thanks tons....
The following code was done in VBA. -
Sub Test()
-
Debug.Print Fix_Path("c:text.txt")
-
Debug.Print Fix_Path("c:\text.txt")
-
End Sub
-
-
Private Function Fix_Path(file_path) As String
-
Dim regex As Object
-
-
Set regex = CreateObject("VBScript.RegExp")
-
regex.Global = True
-
regex.Pattern = ":\\*"
-
Fix_Path = regex.Replace(file_path, ":\")
-
End Function
-
Or, - Sub Test()
-
Dim file_path As String
-
-
file_path = "c:text.txt"
-
Debug.Print Replace(file_path, ":", ":\")
-
End Sub
It's important to note that this sort of unconditional replacement will only work properly if you can absolutely guarantee that the original string cannot have the backslash there already.
If that's the case, then fine. Otherwise you will need your code to check before changing. It could be something simple like using the Mid() function to see whether you have ":" in the second position, and whether you have "\" in the third.
Even though this is probably not a really serious case, it does highlight up a very serious point. In programming, it's vitally important to make a distinction between things which cannot happen, and things which won't happen. You have to follow Murphy's law and assume that if something can go wrong, it will (usually when you're not around to fix it). One of the easiest ways to introduce bugs in your code is to believe someone who tells you "oh it's alright, we would never do that".
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Anand Pillai |
last post by:
To search a word in a group of words, say a paragraph or a web page,
would a string search or a regexp search be faster?
The string search would of course be,
if str.find(substr) != -1:...
|
by: Ken Fine |
last post by:
I'm looking to find or create an ASP script that will take a string, examine
it for a search term, and if it finds the search term in the string, return
the highlighted search term along with the...
|
by: Jason Gleason |
last post by:
What's the most efficient way to get the number of occurences of a certain
string in another string..for instance i'm using the following code right
now...
private int CharacterCounter(String...
|
by: Julie |
last post by:
What is the *fastest* way in .NET to search large on-disk text files (100+ MB)
for a given string.
The files are unindexed and unsorted, and for the purposes of my immediate
requirements, can't...
|
by: Chuck Bowling |
last post by:
I'm having problems doing an efficient keyword search on a text file likely
to be smaller than 100k. I have a keyword list of about 200 strings and I
need to search the file and mark all of the...
|
by: Nikos |
last post by:
Hi... I would like to search for a hex string (for example: "E903") inside a
binary file...
Although I open the file correctly, how do I search hex values?
Thanks in advance!
Nikos
|
by: tshad |
last post by:
Can you do a search for more that one string in another string?
Something like:
someString.IndexOf("something1","something2","something3",0)
or would you have to do something like:
if...
|
by: Imran Aziz |
last post by:
Hello All,
I am getting the following error on our production server, and I dont
get the same error on the development box.
Unable to cast object of type 'System.Byte' to type 'System.String'.
...
|
by: gary |
last post by:
How would one make the ECMA-262 String.replace method work with a
string literal?
For example, if my string was "HELLO" how would I make it work
in this instance.
Please note my square...
|
by: S |
last post by:
Any idea on how I would be able to do a search within C# that does
ranges or words
For example
I want to search for Chicken in the string
string s1 = "This is Great Chicken";
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |