none
Keeping only the first character in a textBox string RRS feed

  • Question

  • Hello there, 

    I want to keep the first character in a string. I have this is what I tried : 

    If AevionRadioButton2.Checked Then
                        RichTextBox1.Rtf = "{\rtf1\ansi\deff0 {\fonttbl{\f0 Times New Roman;}}  " &
                           vbNewLine &
                              "- " & TextBox1.Text.Substring(2, 5) & "," &
                              TextBox2.Text & ", " &
                              "\i " & TextBox5.Text & ". " & "\i0 " &
                              TextBox9.Text & ", " &
                              TextBox10.Text & ". "
                        'Last, F. M. (Year Published) Book. City, State: Publisher.
                    End If

    I am talking about the first character in textBox1.text, <g class="gr_ gr_24 gr-alert gr_tiny gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" data-gr-id="24" id="24">i</g> want to keep only the first character, regardless <g class="gr_ gr_23 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" data-gr-id="23" id="23">to</g> the number of characters.

    thank you.




     



    • Edited by dabezine Sunday, August 26, 2018 2:29 PM
    Sunday, August 26, 2018 2:14 PM

Answers

  • Hi

    This code shows how to get the first character from TextBox1, both as a String and as a Char.

        TextBox1.Text = "Getting the first character!"
        Dim firstcharasstring As String = TextBox1.Text.Substring(0, 1)
        Dim firstcharaschar As Char = TextBox1.Text.ToArray()(0)


    Regards Les, Livingston, Scotland


    • Edited by leshay Sunday, August 26, 2018 2:50 PM
    • Marked as answer by dabezine Monday, August 27, 2018 2:29 PM
    Sunday, August 26, 2018 2:44 PM
  •  If you only want the first letter then any of the following ways will work...

    TextBox1.Text(0)  'gets 1st letter only
    
    TextBox1.Text.Substring(0, 1) 'gets 1st letter only
    
    TextBox1.Text.Remove(1) 'removes all but 1st letter


    If you say it can`t be done then i`ll try it

    • Marked as answer by dabezine Monday, August 27, 2018 2:29 PM
    Sunday, August 26, 2018 2:48 PM
  • The next expressions can be tried too: TextBox1.Text.First and Left(TextBox1.Text, 1).



    • Edited by Viorel_MVP Sunday, August 26, 2018 5:36 PM
    • Marked as answer by dabezine Monday, August 27, 2018 2:31 PM
    Sunday, August 26, 2018 5:36 PM

All replies

  • Hi

    This code shows how to get the first character from TextBox1, both as a String and as a Char.

        TextBox1.Text = "Getting the first character!"
        Dim firstcharasstring As String = TextBox1.Text.Substring(0, 1)
        Dim firstcharaschar As Char = TextBox1.Text.ToArray()(0)


    Regards Les, Livingston, Scotland


    • Edited by leshay Sunday, August 26, 2018 2:50 PM
    • Marked as answer by dabezine Monday, August 27, 2018 2:29 PM
    Sunday, August 26, 2018 2:44 PM
  •  If you only want the first letter then any of the following ways will work...

    TextBox1.Text(0)  'gets 1st letter only
    
    TextBox1.Text.Substring(0, 1) 'gets 1st letter only
    
    TextBox1.Text.Remove(1) 'removes all but 1st letter


    If you say it can`t be done then i`ll try it

    • Marked as answer by dabezine Monday, August 27, 2018 2:29 PM
    Sunday, August 26, 2018 2:48 PM
  • The next expressions can be tried too: TextBox1.Text.First and Left(TextBox1.Text, 1).



    • Edited by Viorel_MVP Sunday, August 26, 2018 5:36 PM
    • Marked as answer by dabezine Monday, August 27, 2018 2:31 PM
    Sunday, August 26, 2018 5:36 PM
  • Thank you very much, sir, for your help! 
    Monday, August 27, 2018 2:32 PM
  • Thank you <g class="gr_ gr_54 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" data-gr-id="54" id="54"><g class="gr_ gr_53 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" data-gr-id="53" id="53">sir</g> ,</g> I appreciate your help! 
    Monday, August 27, 2018 2:33 PM
  • Thank you <g class="gr_ gr_7 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="7" id="7">siir</g> , for your help 
    Monday, August 27, 2018 2:33 PM
  • Thank you a lot sir for helping me.
    Monday, August 27, 2018 2:33 PM