Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.Net - Remove Text Between Characters

Posted on 2015-02-09
9
Medium Priority
?
366 Views
Last Modified: 2015-02-11
Good Day Experts!

I have quite the little project here today.  I need to remove text between 2 characters and also remove the 2 characters.  This happens 2 times in a line.  It "feels" like it is fairly attainable but I cannot seem to find a solution.  Here is a sample of what I am looking at:

GBP       British Pound       0.6528 <http://exchangerates.us2.list-manage2.com/track/click?u=216e81aed0649ca9d1a45cc41&id=bdcf3f2cf0&e=a2e1cf5770>        1.5318 <http://exchangerates.us2.list-manage2.com/track/click?u=216e81aed0649ca9d1a45cc41&id=47712730df&e=a2e1cf5770>       

This is all 1 line in Textpad. I need to remove the text between both sets of <> as well as the <>. So I need to be left with:

GBP       British Pound       0.6528 1.5318

Is this a pretty straight forward endeavor? Can you help me get started with a few tips?

Thanks,
jimbo99999
0
Comment
Question by:Jimbo99999
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 13

Accepted Solution

by:
LIONKING earned 800 total points
ID: 40598572
Quick and dirty way... You can find the substring by finding the < and > symbols, then do that two times (one for each link).

I'm sure there's a neater and more elegant way, I'm just typing this out of the top of my head.
0
 
LVL 34

Assisted Solution

by:it_saige
it_saige earned 400 total points
ID: 40598631
An implementation of a quick and dirty method:
Module Module1
	Sub Main()
		Dim gbp = "GBP       British Pound       0.6528 <http://exchangerates.us2.list-manage2.com/track/click?u=216e81aed0649ca9d1a45cc41&id=bdcf3f2cf0&e=a2e1cf5770>        1.5318 <http://exchangerates.us2.list-manage2.com/track/click?u=216e81aed0649ca9d1a45cc41&id=47712730df&e=a2e1cf5770>"
		Dim index As Integer = gbp.IndexOf("<")
		While (index <> -1)
			If gbp.IndexOf(">", index) <> -1 Then
				gbp = String.Format("{0}{1}", gbp.Substring(0, index), gbp.Substring(gbp.IndexOf(">", index) + 1))
			End If
			index = gbp.IndexOf("<", index + 1)
		End While
		Console.WriteLine(gbp)
		Console.ReadLine()
	End Sub
End Module

Open in new window

Produces the following output -Capture.JPG-saige-
0
 
LVL 64

Assisted Solution

by:Fernando Soto
Fernando Soto earned 400 total points
ID: 40598641
Hi jimbo99999;

This should do what you need.
Imports System.Text.RegularExpressions


'' Test Data
Dim data = "GBP       British Pound       0.6528 <http://exchangerates.us2.list-manage2.com/track/click?u=216e81aed0649ca9d1a45cc41&id=bdcf3f2cf0&e=a2e1cf5770>        1.5318 <http://exchangerates.us2.list-manage2.com/track/click?u=216e81aed0649ca9d1a45cc41&id=47712730df&e=a2e1cf5770>      "
'' Remove URL's from the string and trim any white spaces from the start and end
data = Regex.Replace(data, "<http[^>]*>\s*", String.Empty).Trim()

Open in new window


Resulting string.
GBP       British Pound       0.6528 1.5318
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

Expert Comment

by:it_saige
ID: 40598656
A change to the substring code presented above:
Module Module1
	Sub Main()
		Dim gbp = "GBP       British Pound       0.6528 <http://exchangerates.us2.list-manage2.com/track/click?u=216e81aed0649ca9d1a45cc41&id=bdcf3f2cf0&e=a2e1cf5770>        1.5318 <http://exchangerates.us2.list-manage2.com/track/click?u=216e81aed0649ca9d1a45cc41&id=47712730df&e=a2e1cf5770>"
		Dim index As Integer = gbp.IndexOf("<")
		While (index <> -1)
			If gbp.IndexOf(">", index) <> -1 Then
				gbp = String.Format("{0}{1}", gbp.Substring(0, index), gbp.Substring(gbp.IndexOf(">", index) + 1))
			End If
			' Have to ensure that the index does not surpass the length
			index = gbp.IndexOf("<", If(index + 1 > gbp.Length, 0, index + 1)) 
		End While
		Console.WriteLine(gbp)
		Console.ReadLine()
	End Sub
End Module

Open in new window


Otherwise the output is the same.

-saige-
0
 
LVL 34

Expert Comment

by:it_saige
ID: 40598659
@Fernando, nice regex.  ;)

-saige-
0
 
LVL 22

Assisted Solution

by:rspahitz
rspahitz earned 400 total points
ID: 40598660
Regex could probably handle this well, but I'm not very versed in that.  I'd simply do this:

(assuming that text is stored in a variable called conversion:
Dim iLeftBracketPosn As Integer
Dim iRightBracketPosn As Integer 
Do
   iLeftBracketPosn = conversion.IndexOf("<")
   iRightBracketPosn = conversion.IndexOf(">")
   If iLeftBracketPosn < 0 Or iRightBracketPosn < 0 Then
      Exit Do
   End If
   conversion = conversion.Substring(0, iLeftBracketPosn - 1) & conversion.Substring(iRightBracketPosn + 1)
Loop

Open in new window


(Do a quick check on that to ensure that the left and right brackets are removed and the adjacent text is intact; otherwise you may need to +/- 1 to fix it.)
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40598743
If you are attempting to do this wholly in TextPad, then Fernando's regex should work there to. Just be sure to check the "Regular expression" box and leave the Replace box blank in Find/Replace.
0
 

Author Comment

by:Jimbo99999
ID: 40599098
Thanks everyone for the responses.  I will be working on this shortly.
0
 

Author Closing Comment

by:Jimbo99999
ID: 40604185
Thanks everyone for the help.  Lionking spurred my thought process and went went down the path of that suggestion.  I liked the other ways for my toolbox.

Thanks again,
jimbo99999
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

719 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