Solved

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

Posted on 2012-04-12
4
200 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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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 we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

717 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