Solved

extract string from column

Posted on 2012-03-26
6
367 Views
Last Modified: 2012-08-13
I have the following situation:

I have a column that is contains the following data (string):

A0000AXYZTI00
A0000A12345TI00
etc..

I need to obtain the string value that starts with the 2nd 'A' and ends before the 'T'
So in this case it would be AXYX abd A12345. Sometimes the length between the 2nd A and the T varies. Is there an easy way of doing this with some sort of string function?

Many thanks.
0
Comment
Question by:BauwensER
6 Comments
 
LVL 10

Accepted Solution

by:
MadShiva earned 500 total points
ID: 37770032
Dear,

Something like this should work :

text = "A0000AXYZTI00"

long_text = Len(text)

pos_t = Instr (1, text , "T")  
pos_2nd_a = Instr (2, text , "A")  

value = Mid("A0000AXYZTI00", pos_2nd_a+1, pos_t-pos_2nd_a)

Open in new window

0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 37770060
in query
Select Mid("A0000AXYZTI00", Instr (2, text , "A")  +1 ,Instr (1, text , "TI00") )
0
 

Author Comment

by:BauwensER
ID: 37770073
I just tried value: Mid([MFAnumber], Instr (2, [MFAnumber], "A")  +1 ,Instr (1, [MFAnumber], "TI00") ) but it does not return the right values.
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 29

Expert Comment

by:Badotz
ID: 37770098
Something like this, perhaps:
Function Splitter(str)
    Dim ra
    Dim rb

    ra = Split(str, "T") '' "T" segment(s)
    rb = Split(ra(0), "A") '' "A" segment(s)

    Splitter = "A" & rb(2) '' Return value
End Function

MsgBox Splitter("A0000AXYZTI00") '' "AXYZ"
MsgBox Splitter("A0000A12345TI00") '' "A12345"

Open in new window

0
 
LVL 10

Expert Comment

by:MadShiva
ID: 37770118
Select Mid([MFAnumber], Instr(2, [MFAnumber], "A")+1 ,Instr(1,[MFAnumber], "T")- Instr(2, [MFAnumber], "A")-1)
0
 
LVL 29

Expert Comment

by:Badotz
ID: 37770189
You want concise? You get concise!

Put this in a module:
Function Splitter(ByVal str As String) As String
    Splitter = "A" & Split(Split(str, "T")(0), "A")(2)
End Function

Open in new window

Assume

A1 = "A0000AXYZTI00"

and

A2 = "A0000A12345TI00"

Enter
=Splitter(A1)

Open in new window

into B1 and copy it down to B2.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now