Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 14th, 2007, 03:50 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
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?

Reply With Quote
  #2 (permalink)  
Old April 15th, 2007, 09:49 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,413
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
Reply With Quote
  #3 (permalink)  
Old April 16th, 2007, 08:11 AM
Registered User
 
Join Date: Apr 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

dffdsdf
Reply With Quote
  #4 (permalink)  
Old May 3rd, 2007, 06:54 AM
Authorized User
 
Join Date: Dec 2004
Location: Swindon, Wilts, United Kingdom.
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
Reply With Quote
  #5 (permalink)  
Old May 4th, 2007, 01:46 AM
Authorized User
 
Join Date: Jul 2003
Location: , , .
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.

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 08:57 AM
String Manipulation Ben Access VBA 2 July 8th, 2003 05:53 AM



All times are GMT -4. The time now is 12:46 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.