none
How can i put a string anywhere in a text? RRS feed

  • Question

  • Hi all,

    I would like to put a string

      Dim Volume_level As String = "<volume level=" & NumericUpDown1.Value & ">"

    Anywhere in a textbox full of text. How is this possible? Also how can i put quations around the  NumericUpDown1.Value? The output of volume level should be (<volume level="50">)

    Many thanks for any replies

    • Edited by Pilot_ Monday, September 1, 2008 3:22 AM update
    Monday, September 1, 2008 3:18 AM

Answers

  • Use TextBox.SelectionStart to get the current caret position.
    Hans Passant.
    • Marked as answer by Pilot_ Monday, September 1, 2008 10:33 PM
    Monday, September 1, 2008 9:30 PM
    Moderator

All replies

  • Dim Volume_level As String = "<volume level=""" & NumericUpDown1.Value & """>"
     yourTextBox.Text = yourTextBox.Text.Insert(position, Volume_level)

    Mattias, C# MVP
    Monday, September 1, 2008 9:15 AM
  • Name position is not decleared. Any ideas how to fix this?
    Monday, September 1, 2008 4:58 PM
  • Review the MSDN Library article for String.Insert().
    Hans Passant.
    Monday, September 1, 2008 8:28 PM
    Moderator
  • I don't think is that simple.  I need to obtain somehow the current cursor position before passing it to insert. Any ideas how to do that?

    Giannis
    Monday, September 1, 2008 9:23 PM
  • Use TextBox.SelectionStart to get the current caret position.
    Hans Passant.
    • Marked as answer by Pilot_ Monday, September 1, 2008 10:33 PM
    Monday, September 1, 2008 9:30 PM
    Moderator