Subscribe to Subscribers

Forums » .NET » .NET »

Help need with Regular Expression in C#


Posted Date: 11 Jan 2008      Posted By:: Manoj V     Member Level: Bronze    Member Rank: 0     Points: 2   Responses: 2



I have a string s="kYY2034924324YYYYYYYGdsfjldksjdsjfflYYYYYYY1234YY".

I need to replac YY ( NOT YY in YYYYYYY) with 'xx'.
i.e output must be "kxx2034924324YYYYYYYGdsfjldksjdsjfflYYYYYYY1234xx"

Pls help. Urgent.




Responses

#178436    Author: Subhashini Janakiraman      Member Level: Silver      Member Rank: 1714     Date: 11/Jan/2008   Rating: 2 out of 52 out of 5     Points: 2

Iam just puzzled by the question.Here is my answer.Here when you execute the procedure you will get the solution in vb.net
In a procedure by name change2,
public sub change2()
dim s as string="kYY2034924324YYYYYYYGdsfjldksjdsjfflYYYYYYY1234YY".
dim arr(s.length-1) as char
dim i as integer
dim str as string=""
for i=0 to s.length-1
arr(i)=s.substring(i,1)
next
Do while(i<=s.length-1)
if arr(i)="Y" then
if arr(i+1)="Y" then
if arr(i+2)<>"Y" then
arr(i)="X"
arr(i+1)="X"
endif
endif
endif
i=i+1
Loop
for i=0 to s.length-1
str=str& arr(i)
Next
textbox1.text=str
end sub

IF you want the solution in C#.net
public static void change2()
{
string s="kYY2034924324YYYYYYYGdsfjldksjdsjfflYYYYYYY1234YY";
int i;
char[] arr=new char[s.length];
while(i<s.length)
{
char a=Convert.toChar(s.substring(i,1));
arr[i]=a;
i=i+1;
}
for(i=0;i<s.length-3;i++)
{
if(arr[i]=='Y')
{
If(arr[i+1]=='Y')
{
if(arr[I+2]!='Y')
{
arr[i]='x';
arr[i+1]='x';
}
}
}
i=i+1;
}
for(i=0;i<s.length;i++)
{
string str=str+arr[i];
}
Console.WriteLine("The new string is "+str);
}
Dear Manoj,
When I tried this program in computer it did not work out.Sorry.Hope you will find suitable solution .


 
#178451    Author: Manoj V      Member Level: Bronze      Member Rank: 0     Date: 11/Jan/2008   Rating: 2 out of 52 out of 5     Points: 2

Thank you very much for providing the solutin, Subhashini Janakiraman.

 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : send query for update and delete
Previous : GC
Return to Discussion Forum
Post New Message
Category:

Related Messages

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2013 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.