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
Post a Comment