Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C# Programming

C# Programming C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived from C and C++. It also borrows a lot of concepts from Java too including garbage collection.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-31-2007, 05:38 AM
nikesh nikesh is offline
Newbie
 
Join Date: Aug 2007
Posts: 1
Rep Power: 0
nikesh is on a distinguished road
Default Help ... String replacement with Regex

Hi All,

I have a string in following format

abc;h=v8/35bf/3/0/*/k;

In above string I need to replace everything that comes between two ";" (semi colon), moreover the length between these two ";" can vary

I need to replace the above string with...

abc;junk;

Thanks
Nikesh
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 08-31-2007, 08:39 AM
TkTech TkTech is offline
 
Join Date: Jun 2006
Posts: 987
Last Blog:
Having trouble with yo...
Rep Power: 20
TkTech is on a distinguished road
Send a message via MSN to TkTech
Default

I never use Regex for replacment, just parseing. However, the lookup query will be ;*.; which will grab everything between the semicolens.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-14-2007, 03:11 PM
millepag millepag is offline
Newbie
 
Join Date: Sep 2007
Posts: 2
Rep Power: 0
millepag is on a distinguished road
Default

I agree with TkTech, I wouldn't use regex to do what you want to do. I would do something like this:

Code:
private string replace(string value)
{
    string[] valueSplit = value.Split(';');
    valueSplit[1] = "junk";
    return String.Join(";", valueSplit);
}
Anyway, with regex you would do it something like this:
Code:
private string replace(string value)
{
    System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(";.*;");
    return regex.Replace(value, ";junk;");
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
need help in counting a specify character in a string. lichy Perl 2 06-27-2007 11:03 PM
[Help] String manipulation. afiser Visual Basic Programming 1 05-31-2007 04:24 PM
Tutorial: C# Regex NeedHelp CSharp Tutorials 2 05-01-2007 07:44 AM
Accessing a string by array Saint C# Programming 3 10-03-2006 08:33 PM
regex (yuck) John PHP Forum 9 08-09-2006 01:35 AM


All times are GMT -5. The time now is 08:10 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 97%

Ads