Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 14th, 2007, 03:50 PM
Authorized User
 
Join Date: Jul 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default String manipulation

I have an .aspx file with a string that is one line of data, this line has multiple instances of "ServiceName=" i'm working on a program that extracts each "ServiceName=" from the file, but using sting.INdexof only give me the first instance of "ServiceName=" how do iterate through all instances of "ServiceName=" when it is read as one line?

 
Old April 15th, 2007, 09:49 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Are the occurrences of each item separated by something? If they are, you could split the string into an array, then parse each array item for the name(s) you are looking for.

-Peter
 
Old April 16th, 2007, 08:11 AM
Registered User
 
Join Date: Apr 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

dffdsdf
 
Old May 3rd, 2007, 06:54 AM
Authorized User
 
Join Date: Dec 2004
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DZukiewicz
Default

Hi,

Alternatively, you can use a Regular Expression to get the value, and it will return an matching groups. Regular Expressions sound a bit overkill, but in your example, no knowledge is required.

Code:
using System.Text.RegularExpressions;

string text = "ServiceName=";

MatchCollection matches = Regex.Match(sourceString, text, RegexOptions.SingleLine);

if(matches.Count==0)
     //No matches found
else
{
     foreach(Match m in matches)
     {
          //Match is contained at m.Value;
     }
}
I hope this helps,

Regards,

Dominic
 
Old May 4th, 2007, 01:46 AM
Authorized User
 
Join Date: Jul 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dominic

Thanks! this is very helpful, i want my program to be as robust as possible and the process you have outlined is much more efficent than the process I had come up with.






Similar Threads
Thread Thread Starter Forum Replies Last Post
String manipulation Franco1 Visual Basic 2005 Basics 1 July 16th, 2008 12:53 PM
String manipulation john316 SQL Language 1 October 1st, 2007 04:24 PM
String manipulation pcase XSLT 5 June 14th, 2007 10:32 AM
String Manipulation twsinc Access 3 February 23rd, 2004 09:57 AM
String Manipulation Ben Access VBA 2 July 8th, 2003 05:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.