Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL command to extract text from a varchar(MAX) field based on spaces of text after a specific name 1

Status
Not open for further replies.

jchewsmith

Technical User
Nov 20, 2006
161
US
I am trying to extract only the "0606100000" from below: What is the best way to accomplish this?

varchar field info: a:8:{s:15:"info_buyRequest";a:9:
{s:4:"uenc";s:116:"aHR0cDovL2IyYi5zdXR0bGUtc3RyYXVzLmNvbS9DL2NsZWFyY2hv
aWNlL3dlYjJwcmludC9lZGl0b3IvbG9hZC90eXBlL3Byb2R1Y3QvaWQvNDc0Lw,,";s:7:"
product";s:3:"474";s:15:"related_product";s:0:"";s:10:"product_id";s:3:
"474";s:17:"chili_document_id";s:36:"92026af7-455e-4ccc-a801-
186f4f6a56d2";s:3:"qty";s:3:"500";s:4:"type";s:7:"product";s:2:"id";s:3
:"474";s:7:"options";a:1:{i:154;s:11:"Susie Smith";}}s:7:"options";a:1:
{i:0;a:7:{s:5:"label";s:27:"Enter Name on Business
Card";s:5:"value";s:11:"Susie Smith";s:11:"print_value";s:11:"Susie
Smith";s:9:"option_id";s:3:"154";s:11:"option_type";s:5:"field";s:12:"o
ption_value";s:11:"Susie
Smith";s:11:"custom_view";b:0;}}s:17:"giftcard_lifetime";N;s:22:"giftca
rd_is_redeemable";i:0;s:23:"giftcard_email_template";N;s:13:"giftcard_t
ype";N;s:17:"document_id";s:36:"92026af7-455e-4ccc-a801-
186f4f6a56d2";s:17:"jurisdiction_code";s:10:"0606100000";}
 
Is it ALWAYS last 10 characters before [tt]";} [/tt] at the end?

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
No, just always after the "jurisdiction_Code" lable.
 
Some assumptions and settings:
1. I have your string in a text file [tt]C:\TEMP\MyTextFile.txt[/tt]
2. What you are looking for is placed after [tt]jurisdiction_Code[/tt] plus 8 characters [blue][tt]";s:10:"[/tt][/blue]
3. The portion of the text you are looking for is 10 characters long.

Code:
Dim s As String = ""
Dim s1 As String = "jurisdiction_Code"
Dim tr As IO.TextReader = New IO.StreamReader("C:\TEMP\MyTextFile.txt")
Dim intStart As Integer = 0

s = tr.ReadToEnd

intStart = Strings.InStr(UCase(s), UCase(s1)) + Strings.Len(s1) + 8

MessageBox.Show(Strings.Mid(s, intStart, 10))

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Is there a way to do it if the string is just a varchar(MAX) field in my database?

Thanks for all of your help!!
 
I work with Oracle and I can write a simple Function (stored in the data base) where I can pass a parameter, do some logic like I did above, and return a result. Then I can use this Function anywhere I need it, like:
[tt]
Select Some Field, MyFunction(SomeOtherField) As ABCD
From MyTable
Where ...
[/tt]
I know you can do the same in Access, SQL, etc.


Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top