Click here to Skip to main content
15,910,661 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
What is the meaning of Textbox1.text.trim().Replace("*", "%") ?
is it for replacing entire string??
what is the meaning of this .Replace("?", "_%")??
Posted

It replaces all the * in the textbox text with % and the latter one replaces the ? with _%.
 
Share this answer
 
Comments
Manas Bhardwaj 18-Jun-12 7:18am    
correct +5
Pankaj Nikam 18-Jun-12 7:24am    
Thank you :)
VJ Reddy 20-Jun-12 22:45pm    
Good answer. 5!
Pankaj Nikam 20-Jun-12 23:39pm    
Thank you VJ :)
You can get the answer yourself by writing few lines of code. Isn't it the beauty of programming that you get the result immmediatly?

Anyways, try this:
C#
string input = "***Lets try to understand Replace function.*** Should not be that diffcult ?";

           Console.WriteLine(input);

           Console.WriteLine(input.Replace("*", "%"));

           Console.WriteLine(input.Replace("?", "_%"));


I hope you get the answer yourself. Trust me, it gives a great feeling. :)
Read more about it here:

http://www.dotnetperls.com/replace[^]

http://msdn.microsoft.com/en-us/library/fk49wtc1.aspx[^]
 
Share this answer
 
Comments
Prasad_Kulkarni 18-Jun-12 7:21am    
Well explained! +5
Manas Bhardwaj 18-Jun-12 7:27am    
thx!
Pankaj Nikam 18-Jun-12 7:24am    
Loved the way you explained it :)
Manas Bhardwaj 18-Jun-12 7:27am    
Thx :).
VJ Reddy 20-Jun-12 22:45pm    
Good answer.5!
Textbox1.text.trim().Replace("*", "%") . it replace all "*" with "%" in textbox1.text

if in textbox1.text has
"What is * profit in my * investment"
it will become
"What is % profit in my % investment"
 
Share this answer
 
Comments
Manas Bhardwaj 18-Jun-12 7:18am    
correct +5
VJ Reddy 20-Jun-12 22:46pm    
Good answer. 5!
It returns a new string; in which all occurrences of a specified string in the current instance are replaced with another specified string.

In your example Textbox1.text.trim().Replace("*", "%") it just replaces all '*' with '%'
Refer: String.Replace Method (String, String)[^]

Also have look on: C# Replace[^]
 
Share this answer
 
Comments
Manas Bhardwaj 18-Jun-12 7:18am    
correct +5
Prasad_Kulkarni 18-Jun-12 7:20am    
Thank you Manas!
VJ Reddy 20-Jun-12 22:46pm    
Good answer. 5!
Prasad_Kulkarni 20-Jun-12 23:36pm    
Thank you VJ! Nice to see you, much busy from some days, work load??
VJ Reddy 21-Jun-12 0:21am    
Thank you, Prasad.

I have some additional work during these days. So, I want to return here after some time.

It is a nice experience being on CodeProject sharing the ideas and getting enriched with great coding from experts.
Replace function replace with Old character with New character

Eg :- if Input :- str= Microsoft

str = str.Replace("o","B");

Then output is: MicrBsBft
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900