Solved

Comparing a string to a line of text in a text file

Posted on 2012-04-12
4
199 Views
Last Modified: 2012-04-17
I currently have a value (strString) that may be something like this:

mwmiller78ANDsons

I want to search a text file to see if there is the same value but with spaces

i.e. mwmiller78 and sons

If the program finds such a value, it needs to replace strString with the new found value. If it locates such a value, the cycle will end otherwise it will end at EOF.

How would I do this?
TIA
0
Comment
Question by:Mike Miller
[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
  • 2
4 Comments
 
LVL 14

Expert Comment

by:binaryevo
ID: 37839389
Take the string you wish to compare ( IE:  a line of text from the text file ) and something like this:

Dim newString as String = myComparingString.Replace("mwmiller78ANDsons", "new string value")

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37839438
Try following

For each Line As String in IO.Files.ReadAllLines("path")
     if Line.Contains(" " & strString & " ") Then
        'Not sure what you mean by [i]If the program finds such a value, it needs to replace strString with the new found value. [/i]
     End If
Next

Open in new window

0
 

Accepted Solution

by:
Mike Miller earned 0 total points
ID: 37839604
Got it. Here's what I meant. (Can obviously be simplified...my rough draft)

    Public Function FixSpacing(ByVal fs As String)
        Using reader As New System.IO.StreamReader(strTextFile2)
            While Not reader.EndOfStream
                Dim fsLine As String = reader.ReadLine()
                Dim fsLineRem As String = fsLine.ToString.Replace(" ", "")
                If fsLineRem = fs.Trim Then
                    fs = fsLine.ToString
                    Exit While
                End If
            End While
        End Using
        Return fs
    End Function

Open in new window

0
 

Author Closing Comment

by:Mike Miller
ID: 37854966
Figured it out myself
0

Featured Post

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Import MySQL data into MS Access using VB.Net interface 5 51
Access Schema 6 45
"lblTime is not declared" 3 34
vb.net datagrid point 4 22
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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