need help with a string manipulation.

  • Thread starter Thread starter Learner
  • Start date Start date
L

Learner

Hello,
I am trying to create few dynamic controls and once they are rendered
I need to save the information that was entered into these dynamic
fileds.

For instance when I create 3 radio button dynamic controls I get the ID
of this controls as

rdb29OPT0
rdb30OPT1
rdb31OPT2
....

Now I am trying to manipulate the the above string and just try getting
the 29, 30, 31 from them. Can some one help me with how do I just the
values 29 and remove rdbOPT1 for the first string?

Thanks in advance
-L
 
Ahmed said:
Take a look at the "mid" funtion.

And without using the VisualBasic namespace (my preference, not required)
using using the static (Shared in Visual Basic) Substring method:

Dim s As String = "rdb290PT0"
Dim n As String = s.Substring(3, 2)


HTH
Mythran
 
well there could be many values down the line for instance
rdb1234OPT1234 !
out of which I just need the numerical value that is in between 'rdb'
and 'OPT1234'

I am looking for kind of a method that could rdb and also the word that
starts with OPT

Hope this gives a little inside of it.
Thanks
-L
 
Mythran said:
And without using the VisualBasic namespace (my preference, not required)
using using the static (Shared in Visual Basic) Substring method:

Dim s As String = "rdb290PT0"
Dim n As String = s.Substring(3, 2)

Substring is not a Shared member, it is an instance member.
 
I noticed that the number at the end is the same as the number in the
middle. To get the value in at the end you can use the following:

s.Substring(s.IndexOf("OPT") + 3)

And if you want the number in the middle you can use the following:
s.Substring(3, s.IndexOf("OPT") - 3)
 
Hello Learner,

Regex is overkill and overly complex.
Why not just store the number in the control's .Tag property.
Or derive a new control from radiobutton and add a .Identifier property.

-Boo
 
Chris Dunaway said:
Substring is not a Shared member, it is an instance member.

Woops :) I knew that too...don't know why .. at the time .. I thought it
was static lol :P

I stand corrected (not the first time, nor the last, at least it was a
little help in the right direction).

Mythran
 
Hello Ahmed,
Thanks for the help. s.Substring(3, s.IndexOf("OPT") - 3) works in
my case. I didn't know that I can use the IndexOf to get the exact
position of particular charecter in a string. Thats what I was looking
for.

thanks again,
-L
 
You are welcome :)
Hello Ahmed,
Thanks for the help. s.Substring(3, s.IndexOf("OPT") - 3) works in
my case. I didn't know that I can use the IndexOf to get the exact
position of particular charecter in a string. Thats what I was looking
for.

thanks again,
-L
 
Back
Top