Gibt es einen standardwert für leere Textfelder?
-
Gibt es einen Wert, der einer leeren Windows Forms Textbox per Default zugewiesen wird?
Ich will halt prüfen, ob in einem Texfeld etwas steht und wenn nicht, dieses eben bei der bearbeitung überspringen. So was wie:
if (tbx1 != STANDARDWERT) { mystring = tbx1.Text }
Danke!
-
Was hälst du von:
if (tbx1 != String.Empty) { mystring = tbx1.Text }
-
Korrektur:
if (tbx1.Text != String.Empty) { mystring = tbx1.Text }
-
Klingt gut
-
versuchs mal mit
if (tbx1.Text != "") { mystring = tbx1.Text }
-
oder mit
if (tbx1.Text != '') { mystring = tbx1.Text }
-
Dauercoder schrieb:
oder mit
if (tbx1.Text != '') { mystring = tbx1.Text }
Und das hast Du kompiliert?
-
ja, wie php kann man in C# " und ' für strings verwenden (zumindest bei C# 2.0 soweit ich weiß)
-
Operator '!=' cannot be applied to operands of type 'string' and 'char'
-
ja stimmt jetzt wo du es "schreibst", geht natürlich nur so:
// so if ( ! tbx1.Text.Equals( "" ) ) { mystring = tbx1.Text } // oder so if ( ! tbx1.Text.Equals( string.Empty ) ) { mystring = tbx1.Text } // oder auch so if( tbx1.Text.Lengh > 0 ) { mystring = tbx1.Text }
danke für den hinweis