Replace funstion in C# Question

  • Thread starter Thread starter Patrick Olurotimi Ige
  • Start date Start date
P

Patrick Olurotimi Ige

I'm trying to use Replace function in C# but it seems i can't use
it!!!!!!!
I can use it in VB.NET below
strLogonUsr = Replace(User.Identity.Name,"JOHNS\","")
Does anybody knows how i can do this in C#?
Thx
 
I'm trying to use Replace function in C# but it seems i can't use
it!!!!!!!
I can use it in VB.NET below
strLogonUsr = Replace(User.Identity.Name,"JOHNS\","")
Does anybody knows how i can do this in C#?

strLogonUsr = strLogonUsr.Replace(User.Identity.Name,"JOHNS\\","")
 
I believe this code should do the trick:

strLogonUsr = User.Identity.Name.Replace("JOHNS\\","");
 
Mark Rae,
thx for the reply!
I used the code u provided but it gives me an error!
I don't think C# has Replace function!
Any idea how to do this?
 
You're right.
C# doesn't have a built-in Replace function.

You can use this C# Replace function, though :

===================
//Replace string function.
public static String Replace(String oText,String oFind,String oReplace)
{
int iPos=oText.IndexOf(oFind);
String strReturn="";
while(iPos!=-1)
{
strReturn+=oText.Substring(0,iPos) + oReplace;
oText=oText.Substring(iPos+oFind.Length);
iPos=oText.IndexOf(oFind);
}
if(oText.Length>0)
strReturn+=oText;
return strReturn;
}

=======================

Courtesy of Nayan Patel. Submitted to Binary World
http://www.binaryworld.net/Main/CodeDetail.aspx?CodeId=2455



Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
=====================
 
I don't think C# has Replace function!

No, but String does.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
Hi Patrick,

Hope this code will helps u.....

step:1
using System.Text.RegularExpressions;

step:2
strLogonUsr = Regex.Replace(User.Identity.Name,@"JOHN\\","");
 
Can you use System.String in C#?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
System.String is a part of the .NET Framework and therefore you can use it
(and its Replace method) from any .net compatible language including C# and
VB.NET.
 
System.String is a part of the .NET Framework and therefore you can use it
(and its Replace method) from any .net compatible language including C#
and VB.NET.

Yes I know. I'm just slightly puzzled at the negative responses from certain
of this newsgroup's luminaries at my suggestion that the OP could use it...
 
Well first of all the code snippet you originally posted had invalid syntax,
so it could not be used by anyone in any language.
Other than that I think (in their own ways) they were just trying to point
out that the String.Replace method is not specific to C# only.
No hard feelings though. I think I speak for us all when I say that we
appreciate your contributions even if they were slightly imprecise.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top