vb.net - Inserting text after specific tag -
i have text file comprised of different tags. able find out if specific tag exists within document using following...
public class form1 private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click dim text string = io.file.readalltext("c:\example.xtp") dim index integer = text.indexof("<tools>") if index >= 0 ' string in file, starting @ character "<tools>" insert text "test_hello" end if end sub end class
however want enter text after tag when / if found
i using vb.net
try:
private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click dim text string = io.file.readalltext("c:\example.xtp") dim index integer = text.indexof("<tools>") dim countchars integer countchars="<tools>".length if index >= 0 ' string in file, starting @ character "<tools>" insert text "test_hello" text = text.insert(index + countchars, "test_hello") end if end sub
edit if want write final text a/the file , there many ways. suggest one, need search , read , find suitable you:
dim writer system.io.streamwriter writer = new system.io.streamwriter("c:\textfile.txt") '<-- write writer.write(text) writer.close()
Comments
Post a Comment