473,511 Members | 16,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find in string and

34 New Member
Hi,

Would anyone now how to write an instr that would grab only the date from the string below (i.e between the 2 colons)

I have tried multiple times to get this to work to no avail, the colons will NOT always be at character 14, so need to find first ":" then grab the next 8 caracters.

USINAS SID MI:30/12/09:0.3072:85

i would like to achieve the result

30/12/09

so far I have tried using Left with instr and Right - getting very frustrated.

Thanks in advance

Nigel
Jan 12 '10 #1
8 1734
MMcCarthy
14,534 Recognized Expert Moderator MVP
Try this one ...

Expand|Select|Wrap|Line Numbers
  1. Right(Left("USINAS SID MI:30/12/09:0.3072:85", InStr(1, "USINAS SID MI:30/12/09:0.3072:85", "/", vbTextCompare) + 5), 8)
  2.  
Jan 12 '10 #2
NigelBrown
34 New Member
Thanks msquared,
any chance I could put this in a query, dont really want to create a function but will do if it is the best way. I only need to perform this once a day on import for about 50 rows and was trying to just put an make table query on it.
Thanks
Jan 12 '10 #3
NigelBrown
34 New Member
no worries - got it to work - just took the vbtextcompare out. Thanks for this saved me a lot of time
Jan 12 '10 #4
MMcCarthy
14,534 Recognized Expert Moderator MVP
You're welcome, glad you got it to work.
Jan 12 '10 #5
nico5038
3,080 Recognized Expert Specialist
An alternative might be a function:
Expand|Select|Wrap|Line Numbers
  1. Function fncSplit(strInput As String)
  2.    Dim arr
  3.    arr = Split(strInput, ":")
  4.    fncSplit = arr(1)
  5. End Function
  6.  
In a query you can use:
Expand|Select|Wrap|Line Numbers
  1. SELECT fncSplit([Field with colons]), ... FROM tblX
  2.  
Nic;o)
Jan 12 '10 #6
NigelBrown
34 New Member
Hi Guys,

Thanks you both for your answers, both work well, have a quick question, tried to do it myself but can this be modified to dismiss any fields that do not contain any ":" ? - at the moment it either returns the first 8 char with first option, or using the Function it will Error. I have tried writing an imbedded IF statement (i.e. IF(Instr[filed1],1=";", etc ) but cannot solve this. Appreciate the help Nic, Msquared.
Thanks
Jan 13 '10 #7
nico5038
3,080 Recognized Expert Specialist
Try
Expand|Select|Wrap|Line Numbers
  1. Function fncSplit(strInput As String)
  2.  
  3.     Dim arr
  4.  
  5.     if Instr(strInput,":") > 0 then
  6.        arr = Split(strInput, ":")
  7.        fncSplit = arr(1)
  8.     else
  9.        'Empty string , or whatever you want to return
  10.        fncSplit = ""
  11.     end if
  12.  
  13. End Function
  14.  
Nic;o)
Jan 13 '10 #8
NigelBrown
34 New Member
Thanks Nic, should have known that myself - been staring at this far to long - going to take a break I think. Thanks again
Jan 13 '10 #9

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

Similar topics

10
33657
by: hokieghal99 | last post by:
import os, string print " " setpath = raw_input("Enter the path: ") def find_replace(setpath): for root, dirs, files in os.walk(setpath): fname = files for fname in files: find =...
8
2128
by: Jaime Wyant | last post by:
Will someone explain this to me? >>> "test".find("") 0 Why is the empty string found at position 0? Thanks! jw
3
2969
by: Chris Mantoulidis | last post by:
I posted this here one day ago but it seems like it hasn't been put up for some unknown reason. That gives me a chance to say things a bit better in this post. 1st of all let's desribe the...
3
4430
by: Prakash Bande | last post by:
Hi, I have bool operator == (xx* obj, const string st). I have declared it as friend of class xx. I am now able to do this: xx ox; string st; if (&ox == st) { } But, when I have a vector<xx*>...
108
6298
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information about the extended slice that the slice object would...
4
4728
by: KL | last post by:
Hello again, I am still working on this homework assignment and have hit a wall. I have a list that I want to fill with all occurences of img tags from a big string of html code. So I have a...
7
16966
by: tehn.yit.chin | last post by:
I am trying to experiment <algorithm>'s find to search for an item in a vector of struct. My bit of test code is shown below. #include <iostream> #include <vector> #include <algorithm>...
14
22525
by: micklee74 | last post by:
hi say i have string like this astring = 'abcd efgd 1234 fsdf gfds abcde 1234' if i want to find which postion is 1234, how can i achieve this...? i want to use index() but it only give me the...
1
4196
by: vmoreau | last post by:
I have a text and I need to find a Word that are not enclosed in paranthesis. Can it be done with a regex? Is someone could help me? I am not familar with regex... Example looking for WORD:...
11
3681
by: Ko van der Sloot | last post by:
Hello I was wondering which behaviour might be expected (or is required) for the following small program. I would expect that find( "a", string::npos ) would return string::npos but is seems to...
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7138
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...
1
7081
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7510
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...
0
3225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1576
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
447
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.