|
-
Dec 17th, 2008, 06:48 PM
#1
Thread Starter
New Member
[2008] Adding text to the start of each line
Hello all,
I am a computer technician for a local high school. Part of my job is to add new sites to the website filter, as teachers send the links to me. The way our filter works, instead of blocking google.com, I have to type in *\.google\.com*\.*
That does get annoying after a while, as it's quite repetitive. I'm writing a small program to help me with that. There are two multiline text boxes and a button. I enter the URLs into the top text box (one URL per line), and than click the button, and ideally it will automatically add the *\. to the front, the \ in front of .com, and *\.* to the end of each line, and than display the outcome in the lower text box.
I figured out how to add the \ in front of .com:
DotComFiltered = StrReplace (OriginalList, ".", "\.")
However, I can't figure out how to make visual basic add the *\. in front of each line, and the *\.* at the end of each line. Is that possible?
-
Dec 17th, 2008, 06:57 PM
#2
Re: [2008] Adding text to the start of each line
vb.net Code:
Dim lines As String() = myTextBox.Lines For index As Integer = 0 To lines.GetUpperBound(0) lines(index) = String.Format("*\.{0}*\.*", _ lines(index).Replace(".com", _ "\.com")) Next myTextBox.Lines = lines
Just be aware that that Replace will also affect words that begin with "com". You'd probably be better off using Regex.Replace but I'll leave that to you.
-
Dec 24th, 2008, 06:10 AM
#3
Hyperactive Member
Re: [2008] Adding text to the start of each line
hi Joey H
jmcilhinney's solution is pretty good alternatively u may use following code for getting desired output
do not forget to use following at top of ur code window
vb Code:
Imports System.Text.RegularExpressions
call it using following syntax
vb Code:
txtFilter.Text=MakeFilter(txtFilter.Text)
here the MakeFilter function which does desired for you
vb Code:
Public Function MakeFilter(ByVal sInput As String) As String ' here i assume that u r using filter rule in firewall for preventing url to navigate so .(dot) ' must be escaped for it that's why i use following line sInput = Regex.Replace(sInput, "\.", "\.", RegexOptions.Multiline ) ' you may use following line if only .com is to be replaced use ignorecase option for avoiding lower upper case issue ' uncomment it if required and comment the above one ' sInput = Regex.Replace(sInput, "\.com", "\.com", RegexOptions.Multiline Or RegexOptions.IgnoreCase) ' Starting of line sInput = Regex.Replace(sInput, "^", "*\.", RegexOptions.Multiline) ' End of line sInput = Regex.Replace(sInput, "$", "*\.*" + vbNewLine, RegexOptions.Multiline) Return sInput End Function
Last edited by su ki; Dec 24th, 2008 at 06:30 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|