vb.net - Need to exclued enter key from textbox -


the folowing code read text text based file textbox enter key displayed (as 2 small boxes) need code subtract absolute last character in textbox how can done?

    private sub form1_load(byval sender system.object, byval e system.eventargs) handles mybase.load      dim readalpha system.io.streamreader      readalpha = system.io.file.opentext("c:\alpha.val")     textbox1.text = (readalpha.readtoend)     readalpha.close()      dim readbeta system.io.streamreader      readbeta = system.io.file.opentext("c:\beta.val")     textbox2.text = (readbeta.readtoend)     readbeta.close()       'textbox1.text = "<enter first value>"     'textbox2.text = "<enter second value>"  end sub 

you can replace character, this:

textbox2.text = (readbeta.readtoend).replace(environment.newline, " ") 

but it's better check if string null:

string.isnullorempty before.

dim buffer string buffer = readbeta.readtoend if not string.isnullorempty(buffer)    textbox2.text = buffer.replace(environment.newline, " ") end if 

or better, check nasty characters extension method:

imports system.runtime.compilerservices

public module extmethods      <extension()> _     public function replaceenterkeyword(byval value string, optional byval charsubstitution string = "") string         if not string.isnullorempty(value)             value                 value = .replace(microsoft.visualbasic.controlchars.crlf, charsubstitution) _                         .replace(microsoft.visualbasic.controlchars.cr, charsubstitution) _                         .replace(microsoft.visualbasic.controlchars.lf, charsubstitution)             end         end if         return (value)     end function  end module 

and call this:

textbox2.text = buffer.replaceenterkeyword(" "); 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -