Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

substring()

Posted on 2006-11-15
20
Medium Priority
?
433 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
  • 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
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!

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month20 days, 22 hours left to enroll

810 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