• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 131
  • Last Modified:

String manipulation in Visual Basic

Hi,
I've been reading about the Split functions but I have a split on two different characters within a text file.  

The string to parse is <FILENAME>123456789.TIF</FILENAME>

I would like to only extract the information between > and </.   I realize this is xml format, but the document is not an XML document.    The length of the value can vary in size.

Does anyone have any examples or can point me in the right direction?   I've not had any luck so far.   Thanks, Michelle
0
Michelle Aycoth
Asked:
Michelle Aycoth
  • 4
  • 2
1 Solution
 
Martin LissOlder than dirtCommented:
MsgBox Split(Replace(x, ">", "<"), "<")(2)

Where x is your string variable.
1
 
KimputerCommented:
If that's really the string (and not just a part of a much bigger line) it would be

Dim original_string = "<FILENAME>123456789.TIF</FILENAME>"
Dim temp = split(original_string,">")(1)
Dim result = split(temp,"<")(0)
'or one step
result = split(split(original_string,">")(1),"<")(0)

Open in new window


If it's part of a bigger line (or not formatted as predictable), use regex instead.
1
 
Martin LissOlder than dirtCommented:
Some explanation of my code is probably called for. The "Replace" portion of the above changes all ">" to "<" to make what the Split command splits on consistent. Then the (2) portion returns the 3rd entry in the array that Split returns. (0) would be  a blank because there's nothing in front of the first "<" in the modified string, and (1) would be FILENAME.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Michelle AycothAuthor Commented:
Thanks for the quick responses.   I didn't realize I could split on a split.   Thought I had to do some sort of substring configuration.
0
 
Martin LissOlder than dirtCommented:
I assume you were responding to Kimputer. You don't need to Split on Split. Please see my post ID: 41818694.
1
 
Michelle AycothAuthor Commented:
Thanks so much for the quick response.
0
 
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

If you expand the “Full Biography” section of my profile you'll find links to some articles I've written that may interest you.

Marty - Microsoft MVP 2009 to 2016
              Experts Exchange MVE 2015
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2015
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now