| | |
extracting sustrings from a string and store it in an array
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2007
Posts: 33
Reputation:
Solved Threads: 0
Hi
I want to extract sustrings from a string and want to store in an array.
The string is dynamic it will change but the criteria to extract substring is same.
say for example a string str="something is [!better] than [!nothing]"
so i need to extract [!better] and [!nothing] from the string and store it in a string array, the string is dynamic it changes but i need to extract data between [ and ] including both the square brackets.
If anybody can send any sample code, I will be very thankfull.
Thanks
Ansari
I want to extract sustrings from a string and want to store in an array.
The string is dynamic it will change but the criteria to extract substring is same.
say for example a string str="something is [!better] than [!nothing]"
so i need to extract [!better] and [!nothing] from the string and store it in a string array, the string is dynamic it changes but i need to extract data between [ and ] including both the square brackets.
If anybody can send any sample code, I will be very thankfull.
Thanks
Ansari
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
ASP.NET Syntax (Toggle Plain Text)
int openBracket = 0; int closeBracket = 0; ArrayList subs = new ArrayList(); //you'll want to use a loop here to check //if there are no more matches //gets indexes openBracket = str.IndexOf("[", openBracket); closeBracket = str.IndexOf("]", openBracket); //add substring //i think you need the + 1 to include the ']' subs.add(str.substring(openBracket, closeBracket - openBracket + 1)); //resets position openBracket = closeBracket;
Last edited by dickersonka; Sep 16th, 2008 at 11:50 am.
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
![]() |
Other Threads in the ASP.NET Forum
- Previous Thread: working with GRIDVIEW
- Next Thread: using common dialogbox in asp.net
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax alltypeofvideos asp asp.net bc30451 bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn checkbox click commonfunctions compatible confirmationcodegeneration content contenttype countryselector courier css dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dropdownmenu edit expose flash flv formatdecimal forms formview gridview homeedition iframe iis javascript jquery list listbox login menu microsoft mono mouse mssql multistepregistration nameisnotdeclared news numerical objects order panelmasterpagebuttoncontrols problem radio ratings reportemail rotatepage save schoolproject search security serializesmo.table silverlight smartcard software sql-server sqlserver2005 suse textbox tracking unauthorized validation vb.net video videos virtualdirectory vista visual-studio visualstudio web webapplications webarchitecture webdevelopemnt webprogramming webservice xml youareanotmemberofthedebuggerusers






