2012-11-22 5 views
-1

인용 부호로 텍스트를 가져 와서 표시하고 싶습니다.텍스트 가져 오기 및 vb.net에서 바꾸기

이름이 "존"

이름

이 모든 .txt 파일에 "무엇이든"

+2

단지를 검색 : 1.이 정말 가치가 SO 질문이 아닌 내 소견에서 파일에 텍스트를 작성하는 방법 텍스트 상자 (2)에서 텍스트를 얻는 방법 알아 내라, 그것은 매우 구체적인 질문이 아니다, 단지 google. – Aaron

+2

[String.Replace] (http://msdn.microsoft.com/en-us/library/system.string.replace.aspx)를 사용하십시오. – Neolisk

+0

나는 그것을 google했다. –

답변

0

비주얼 베이직을 인터넷 검색을 시도 텍스트 상자에 무엇으로 대체. net + streamreader 및 vb.net + streamwriter 예제를 사용하면 원하는 결과를 얻을 수 있습니다.

+0

나는 파일을 읽는 법을 안다.하지만 단어 이름을 찾으면 인용 부호로 읽는 법을 모른다. –

1

줄 단위로 파일을 읽고 단어 단위로 분할하고 큰 따옴표로 묶은 텍스트를 찾고 텍스트 상자 텍스트로 바꿔야합니다.

나는 코드를 읽고 바꾸도록 지정했습니다. 마지막에 txt 파일에 다시 쓰기 기능을 작성하십시오.

사용법 :

Try 
    ' Create an instance of StreamReader to read from a file. 
    Dim sr As StreamReader = New StreamReader("TestFile.txt") 
    Dim line As String 
    Dim FullContent as string="" 
    ' Read and display the lines from the file until the end 
    ' of the file is reached. 

    Dim strArray() as string=Nothing 

Do 
    Array.Clear(strArray,0,strArray.Length) 
    line = sr.ReadLine() 

    strArray=line.split(" ")  'To read Every Word Seperated by a Space 
    For i=0 to strArray.Count-1 

     'Checks StartsWith and EndsWith "  - Eg. Ashi likes "firefox" 
     If strArray(i).StartsWith("""") and strArray(i).EndsWith("""") then 

      'Replace the string in "firefox" with TextBox1 text 
      line.Replace("""" & strArray(i) & """",trim(TextBox1.Text)) 

     End If 
    FullContent = FullContent & line  'Append the changes to full content 
    Next 


Loop Until line Is Nothing 
    sr.Close() 

    'Now you can write the FullContent Back to Txt File which has the replaced changes 
    'writeFunction(FullContent) 

    'If you want to display, then 
    msgbox(FullContent) 


Catch E As Exception 
    ' Let the user know what went wrong. 
    Console.WriteLine("The file could not be read:") 
    Console.WriteLine(E.Message) 
End Try 
+0

나는 그것을 이해했다. 감사! –

관련 문제