how to get a string?

mzim

Well-known member
Joined
Jun 3, 2004
Messages
187
Location
Other side of the rock
Programming Experience
1-3
hi to everyone,

i would like to ask this stupid question that given me an headache an hour ago..
how to get a string where the cursor is located..
i.e..if i type "wherever will go" and the cursor is in "i" of will...i want to get the string will....
hope i explain it will

thanks and more power..
 
Last edited:

BAH315

New member
Joined
Jun 7, 2004
Messages
1
Location
Holland, OH
Programming Experience
5-10
VB.NET:
[size=1]

[/size][size=1][color=#0000ff]Dim[/color][/size][size=1] i [/size][size=1][color=#0000ff]As[/color][/size][size=1] [/size][size=1][color=#0000ff]Integer[/color][/size][size=1] = [/size][size=1][color=#0000ff]Me[/color][/size][size=1].TextBox1.SelectionStart

[/size][size=1][color=#0000ff]Dim[/color][/size][size=1] sSelected [/size][size=1][color=#0000ff]As[/color][/size][size=1] [/size][size=1][color=#0000ff]String[/color][/size][size=1] = [/size][size=1][color=#800000]""

[/color][/size][size=1][/size][size=1][color=#0000ff]If[/color][/size][size=1] [/size][size=1][color=#0000ff]Me[/color][/size][size=1].TextBox1.Text.Trim.Length = [/size][size=1][color=#800080]0[/color][/size][size=1] [/size][size=1][color=#0000ff]Then

[/color][/size][size=1]MessageBox.Show([/size][size=1][color=#800000]"No text"[/color][/size][size=1])

[/size][size=1][color=#0000ff]Exit[/color][/size][size=1] [/size][size=1][color=#0000ff]Sub

[/color][/size][size=1][/size][size=1][color=#0000ff]End[/color][/size][size=1] [/size][size=1][color=#0000ff]If

[/color][/size][size=1][/size][size=1][color=#0000ff]If[/color][/size][size=1] [/size][size=1][color=#0000ff]Me[/color][/size][size=1].TextBox1.Text.IndexOf([/size][size=1][color=#800000]" "[/color][/size][size=1], i) > -[/size][size=1][color=#800080]1[/color][/size][size=1] [/size][size=1][color=#0000ff]Then

[/color][/size][size=1]sSelected = [/size][size=1][color=#0000ff]Me[/color][/size][size=1].TextBox1.Text.Substring(i, [/size][size=1][color=#0000ff]Me[/color][/size][size=1].TextBox1.Text.IndexOf([/size][size=1][color=#800000]" "[/color][/size][size=1], i) - i)

[/size][size=1][color=#0000ff]Else

[/color][/size][size=1]sSelected = [/size][size=1][color=#0000ff]Me[/color][/size][size=1].TextBox1.Text.Substring(i)

[/size][size=1][color=#0000ff]End[/color][/size][size=1] [/size][size=1][color=#0000ff]If

[/color][/size][size=1][/size][size=1][color=#0000ff]While[/color][/size][size=1] [/size][size=1][color=#0000ff]True

[/color][/size][size=1]i -= [/size][size=1][color=#800080]1

[/color][/size][size=1][/size][size=1][color=#0000ff]If[/color][/size][size=1] i > -[/size][size=1][color=#800080]1[/color][/size][size=1] [/size][size=1][color=#0000ff]Then

[/color][/size][size=1][/size][size=1][color=#0000ff]If[/color][/size][size=1] [/size][size=1][color=#0000ff]Me[/color][/size][size=1].TextBox1.Text.Substring(i, [/size][size=1][color=#800080]1[/color][/size][size=1]) = [/size][size=1][color=#800000]" "[/color][/size][size=1] [/size][size=1][color=#0000ff]Then

[/color][/size][size=1][/size][size=1][color=#0000ff]Exit[/color][/size][size=1] [/size][size=1][color=#0000ff]While

[/color][/size][size=1][/size][size=1][color=#0000ff]Else

[/color][/size][size=1]sSelected = [/size][size=1][color=#0000ff]Me[/color][/size][size=1].TextBox1.Text.Substring(i, [/size][size=1][color=#800080]1[/color][/size][size=1]) & sSelected

[/size][size=1][color=#0000ff]End[/color][/size][size=1] [/size][size=1][color=#0000ff]If

[/color][/size][size=1][/size][size=1][color=#0000ff]Else

[/color][/size][size=1][/size][size=1][color=#0000ff]Exit[/color][/size][size=1] [/size][size=1][color=#0000ff]While

[/color][/size][size=1][/size][size=1][color=#0000ff]End[/color][/size][size=1] [/size][size=1][color=#0000ff]If

[/color][/size][size=1][/size][size=1][color=#0000ff]End[/color][/size][size=1] [/size][size=1][color=#0000ff]While

[/color][/size][size=1]MessageBox.Show(sSelected)

[/size]
 
Top Bottom