473,395 Members | 1,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Replace funstion in C# Question

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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #1
15 1295
"Patrick Olurotimi Ige" <ig*@iprimus.com.au> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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\\"," ")
Nov 19 '05 #2
I believe this code should do the trick:

strLogonUsr = User.Identity.Name.Replace("JOHNS\\","");

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Patrick Olurotimi Ige" <ig*@iprimus.com.au> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 19 '05 #3
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?


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #4
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/Code...px?CodeId=2455

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
=====================

"Patrick Olurotimi Ige" <ig*@iprimus.com.au> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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?


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 19 '05 #5
Thx Steve that did the trick in C#..
Thx for the info.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #6
> 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.

"Patrick Olurotimi Ige" <ig*@iprimus.com.au> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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?


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 19 '05 #7
"Patrick Olurotimi Ige" <ig*@iprimus.com.au> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I don't think C# has Replace function!


http://msdn.microsoft.com/library/de...placetopic.asp
Nov 19 '05 #8
That's *not* a C# function.

It's a method of System.String
( System.String.Replace )

http://www.csharpfriends.com/quickst...m&class=String


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
=====================

"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:uo*************@TK2MSFTNGP12.phx.gbl...
"Patrick Olurotimi Ige" <ig*@iprimus.com.au> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I don't think C# has Replace function!


http://msdn.microsoft.com/library/de...placetopic.asp

Nov 19 '05 #9
Thanks Juan,Steve and Kevin for the reponses..
Patrick

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #10
"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:uK**************@tk2msftngp13.phx.gbl...
That's *not* a C# function.

It's a method of System.String
( System.String.Replace )


Can I not use it in C#, then...?
Nov 19 '05 #11

Hi Patrick,

Hope this code will helps u.....

step:1
using System.Text.RegularExpressions;

step:2
strLogonUsr = Regex.Replace(User.Identity.Name,@"JOHN\\","");


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #12
Can you use System.String in C#?

--
HTH,

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

"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:uX**************@TK2MSFTNGP15.phx.gbl...
"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:uK**************@tk2msftngp13.phx.gbl...
That's *not* a C# function.

It's a method of System.String
( System.String.Replace )


Can I not use it in C#, then...?

Nov 19 '05 #13
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.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:uX**************@TK2MSFTNGP15.phx.gbl...
"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:uK**************@tk2msftngp13.phx.gbl...
That's *not* a C# function.

It's a method of System.String
( System.String.Replace )


Can I not use it in C#, then...?

Nov 19 '05 #14
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:O4**************@TK2MSFTNGP09.phx.gbl...
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...
Nov 19 '05 #15
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.

--
Thanks,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:uU**************@TK2MSFTNGP09.phx.gbl...
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:O4**************@TK2MSFTNGP09.phx.gbl...
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...

Nov 19 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Westcoast Sheri | last post by:
To keep track of how many fruits my visitors buy, I use a mySQL database (2 columns: "fruit" and "quantity")....so can we make these following mySQL queries work somehow? (visitor buys 5...
5
by: Roose | last post by:
How can I do a "".replace operation which tells me if anything was actually replaced? Right now I am doing something like: if searchTerm in text: text = text.replace( searchTerm, 'other' ) ...
4
by: higabe | last post by:
Three questions 1) I have a string function that works perfectly but according to W3C.org web site is syntactically flawed because it contains the characters </ in sequence. So how am I...
22
by: Phlip | last post by:
C++ers: Here's an open ended STL question. What's the smarmiest most templated way to use <string>, <algorithms> etc. to turn this: " able search baker search charlie " into this: " able...
9
by: Not Me | last post by:
Hi, I'm having bother with the replace function in access 2002, a while back I remember not being able to get it to work... then suddenly the next time I tried it did work. Now it doesn't...
3
by: Andy Sutorius | last post by:
Hi, I read the thread (2/16/05) regarding a replace function in C# however it didn't answer my question. I have a string which is building an insert sql statement and I would like to replace...
9
by: Peter Row | last post by:
Hi, I know this has been asked before, but reading the threads it is still not entirely clear. Deciding which .Replace( ) to use when. Typically if I create a string in a loop I always use a...
5
by: djc | last post by:
I need to prepare a large text database field to display in an asp.net repeater control. Currently I am replacing all chr(13)'s with a "<br/>" and it works fine. However, now I also want to be able...
15
by: =?Utf-8?B?TWlrZSAiWU9fQkVFIiBC?= | last post by:
I have a text file that contains about 8 to 10 text sequences that I need to replace. I want to search and replace all 8 to 10 text sequence anytime I run this script Here is what I have so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.