473,407 Members | 2,598 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,407 software developers and data experts.

Substring a variable length field

9
Hi, I'm hoping for some help on how to substring a field using VB. I have fields such as B6002_1.9.6.15CO, 103456_304793. I need the #'s and digits both to the left and right of the underscore as separate fields (B6002 as one field and then 1.9.6.15CO as a second field). The underscore is never in the same position in the field. Can anyone please help? thanks
Feb 16 '09 #1
3 2422
OuTCasT
374 256MB
Dim str as String
str = "B6002_1.9.6.15CO"
str = str.replace("_","#_#")

That will replace the _ with the #_# no matter where it will occur.
Feb 17 '09 #2
Stewart Ross
2,545 Expert Mod 2GB
I think the poster wants to split the string into two components using the underscore as a separator:
'B6002_1.9.6.15CO' >>> 'B6002' and '1.9.6.15CO',
'103456_304793' >>> '103456' and '304793'.

Expand|Select|Wrap|Line Numbers
  1. Dim intPos as Integer
  2. Dim strFirstPart as String, strSecondPart as String
  3. intPos = Instr(CombinedString, "_")
  4. If intPos > 0 Then
  5.     strFirstPart = Left(CombinedString, intPos - 1)
  6.     strSecondPart = Mid(CombinedString, intPos + 1)
  7. End IF
(Mid used without a length parameter returns everything from the given position to the end of the string.)

-Stewart
Feb 17 '09 #3
bae14
9
Thanks for all responses. Actually I got them split and then used the "replace" to remove the underscore. The replace command will really be useful. Thanks. And Stewart, I used a form of your Left and Mid to get the original breakout. I appreciate everyone's help!
Feb 17 '09 #4

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

Similar topics

0
by: KENNY L. CHEN | last post by:
I have a table with a CHAR column which stored a COBOL redefined record. I tried to retrieve part of the field from the column with Oracle substr function. Here is one of example: The...
15
by: Magix | last post by:
hi, let say I have this string +CCED: "xxxxxxxxx", 333 What is the most efficient way to capture the string within the " " ? which is xxxxxxxxx xxxxxxxxx can be any string.
19
by: Skybuck Flying | last post by:
Hi, I think I might have just invented the variable bit cpu :) It works simply like this: Each "data bit" has a "meta data bit". The meta data bit describes if the bit is the ending bit...
11
by: Darren Anderson | last post by:
I have a function that I've tried using in an if then statement and I've found that no matter how much reworking I do with the code, the expected result is incorrect. the code: If Not...
2
by: David Filion | last post by:
Hi, I have a question about substring(), when I run the following query: prepaid=# select substring('15148300', 0, 5); substring ----------- 1514 (1 row)
15
by: Duncan Allen | last post by:
Hi, Using C# I'm trying to use the substring method of a string variable but it just generates an "error: 'variable.Substring' does not exist " exception - how do I fix this ? code example: ...
2
by: Badass Scotsman | last post by:
Hello, Using VB and ASP,NET I would like to be able to search a STRING for a smaller STRING within, based on the characters which appear before and after. For example: String1 = " That was...
6
by: kellygreer1 | last post by:
What is a good one line method for doing a "length safe" String.Substring? The VB classes offer up the old Left function so that string s = Microsoft.VisualBasic.Left("kelly",200) // s will =...
2
by: Daniel Reardon | last post by:
All, I'm sure that this is an old question, but I'm having problems getting a substring of a passed in variable. I can do other string manipulation with it such as concatonation, but I'm really...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.