?
Solved

substring()

Posted on 2006-11-15
20
Medium Priority
?
431 Views
Last Modified: 2012-06-27
i have a string =
"asDfsl00_PlaceHolder1_default_ctl01_ctl43_radiobutton1&info_id=5634&Age=17"

i want the my value to be stored in different variables

string info_id = 5634 (node: can be one number or 5 digits or more)
string age = 17 (note: can be one number of more numbers, i can not control on that)

how do i extract from above string?

0
Comment
Question by:Islam1424
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
  • 6
20 Comments
 
LVL 28

Expert Comment

by:strickdd
ID: 17949810
I'm assuming this is the value or some other property of a place holder so why not try:

((ControlType)PlaceHolder1.FindControl("ControlName")).Property (usually .Text or .SelectedValue)
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17949854
use String.Split on "="
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17949864
str="asDfsl00_PlaceHolder1_default_ctl01_ctl43_radiobutton1&info_id=5634&Age=17"

Dim arrValues() as string
Dim id, age as string

arrValues=str.Split("=")
id=arrValues(arrValues.Length-2)
age=arrValues(arrValues.Length-1)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 35

Expert Comment

by:YZlat
ID: 17949896
actually you'll need


Dim arrValues() As String
        Dim str, infor_id, age As String

        str = "asDfsl00_PlaceHolder1_default_ctl01_ctl43_radiobutton1&info_id=5634&Age=17"

       
        arrValues = Str.Split("=")
        info_id= Replace(arrValues(arrValues.Length - 2), "&Age", "")
        age = arrValues(arrValues.Length - 1)
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17949926
using C#:

string str = "asDfsl00_PlaceHolder1_default_ctl01_ctl43_radiobutton1&info_id=5634&Age=17";
string[] arrValues = Str.Split("=");
string info_id = Replace(arrValues(arrValues.Length - 2), "&Age", "");
string age = arrValues(arrValues.Length - 1);
0
 
LVL 28

Expert Comment

by:strickdd
ID: 17949935
If the case is that it isn't a control inside a control you can do:

string someString = "asDfsl00_PlaceHolder1_default_ctl01_ctl43_radiobutton1&info_id=5634&Age=17";

someString = someString.Substring(someString.IndexOf("info_id=") + 8);

string info_id = someString.Substring(0, someString.IndexOf("&"));
string Age = someString.Substring(someString.IndexOf("&") + 1);
0
 
LVL 28

Expert Comment

by:strickdd
ID: 17950000
sorry:

string Age = someString.Substring(someString.IndexOf("&") + 1);

should be:

string Age = someString.Substring(someString.IndexOf("Age=") + 4);



but once again if you are accessing controls in this placeholder, it is best to type case a findcontrol on the control ID you want to access ie:

((TextBox)PlaceHolder1.FindControl("Age")).Text
0
 

Author Comment

by:Islam1424
ID: 17950326
Yzlat:

Error      2      Argument '1': cannot convert from 'string' to 'char[]'      

Error      3      The name 'Replace' does not exist in the current context      

Error      4      'arrValues' is a 'variable' but is used like a 'method'      

Error      5      'arrValues' is a 'variable' but is used like a 'method'       
0
 

Author Comment

by:Islam1424
ID: 17950360
strickdd :

>but once again if you are accessing controls in this placeholder, it is best to type case a findcontrol on the >control ID you want to access ie:

thanks but i'm not finding any control

but in fact i'm adding into the string and from there i'm extracting.

0
 
LVL 28

Expert Comment

by:strickdd
ID: 17950399
Where is the string being stored? is it the text or the id of the Panel?
0
 

Author Comment

by:Islam1424
ID: 17950416
its storing in the string
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17950424
try replacing

string[] arrValues = Str.Split("=");

with

string[] arrValues = str.Split(new char[] {'='});
0
 

Author Comment

by:Islam1424
ID: 17950428
is it the safe side of doing?

0
 

Author Comment

by:Islam1424
ID: 17950467
string str = "asDfsl00_PlaceHolder1_default_ctl01_ctl43_radiobutton1&info_id=5634&Age=17";
                    string[] arrValues = str.Split(new char[] { '=' });
                    string info_id = Replace(arrValues(arrValues.Length - 2), "&Age", "");
                    string age = arrValues(arrValues.Length - 1);

Error      1      The name 'Replace' does not exist in the current context
Error      2      'arrValues' is a 'variable' but is used like a 'method'
Error      3      'arrValues' is a 'variable' but is used like a 'method'
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17950499
strange... can you post all your code?
0
 
LVL 28

Expert Comment

by:strickdd
ID: 17950505
have you tried this yet:

string someString = "asDfsl00_PlaceHolder1_default_ctl01_ctl43_radiobutton1&info_id=5634&Age=17";

someString = someString.Substring(someString.IndexOf("info_id=") + 8);

string info_id = someString.Substring(0, someString.IndexOf("&"));
string Age = someString.Substring(someString.IndexOf("Age=") + 4);
0
 
LVL 35

Assisted Solution

by:YZlat
YZlat earned 300 total points
ID: 17950556
try this:

string str = "asDfsl00_PlaceHolder1_default_ctl01_ctl43_radiobutton1&info_id=5634&Age=17";
                        string[] arrValues = str.Split(new char[] { '=' });
                        string info_id = arrValues[arrValues.Length - 2];
                              info_id=info_id.Replace("&Age", "");
                        string age = arrValues[arrValues.Length - 1];
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17950560
I used Replace like in VB.NET before. Here is C# version
0
 

Author Comment

by:Islam1424
ID: 17950686
strickdd, yes your approach word

but just want to get some opinion

is that the safe way of extracting?

0
 
LVL 28

Accepted Solution

by:
strickdd earned 200 total points
ID: 17950720
It is not a real dynamic way of doing things, and there is really no good way, unless you add hidden fields to the panel and access those with a foreach loop.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question