Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2012-04-12
4
Medium Priority
?
202 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

597 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