473,394 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

String Search and Add to

50
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....
Jan 30 '08 #1
5 1201
9815402440
180 100+
hi

use inStr() function

usage:

if instr(1,"C:\Tex.text",":") > 0 then
': found
endif

regards
manpreet singh dhillon hoshiarpur
Jan 30 '08 #2
jarremw
50
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....
Jan 30 '08 #3
The following code was done in VBA.

Expand|Select|Wrap|Line Numbers
  1. Sub Test()
  2.    Debug.Print Fix_Path("c:text.txt")
  3.    Debug.Print Fix_Path("c:\text.txt")
  4. End Sub
  5.  
  6. Private Function Fix_Path(file_path) As String
  7.    Dim regex As Object
  8.  
  9.    Set regex = CreateObject("VBScript.RegExp")
  10.    regex.Global = True
  11.    regex.Pattern = ":\\*"
  12.    Fix_Path = regex.Replace(file_path, ":\")
  13. End Function
  14.  
Jan 30 '08 #4
Or,

Expand|Select|Wrap|Line Numbers
  1. Sub Test()
  2.    Dim file_path As String
  3.  
  4.    file_path = "c:text.txt"
  5.    Debug.Print Replace(file_path, ":", ":\")
  6. End Sub
Jan 30 '08 #5
Killer42
8,435 Expert 8TB
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".
Jan 30 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

10
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:...
4
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...
4
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...
60
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...
15
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...
4
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
32
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...
3
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'. ...
21
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...
14
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";
0
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...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
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...
0
jinu1996
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...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.