472,331 Members | 1,728 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

clarifying

static void Main(string[] what) { string test="testing 1 2 3";
test.Replace("testing", "test"); } // why this doesn't replace the word
"testing" ?

when using "try" can i use multiple "block catch" ? // i tried but can't
, this is allowed in java right, how about C#?
ex. catch(exception e) {} catch(FormatException){}
thank you for clarifying


Nov 15 '05 #1
2 1470
Change your proc like this so that you assign test = test.Replace
static void Main(string[] what) {
string test="testing 1 2 3";
test = test.Replace("testing", "test"); //change this line.
} // why this doesn't replace the word "testing" ?

You can and often should have multiple catch blocks. Remember though that
you need to go from most precise to most broad.

If you tried this

catch(System.Exception e){}
cathc(System.FormatException f){}

The compiler will yell about unreachable code. Why? B/c the First catch
block will grab any exception, so if a FormatException was thrown, it would
get caught in the first catch, not the second. If you flip them around, all
will be well. This is important b/c in VB.NET, it wont' bark at you and
could inject subtle logic errors ---and even outside of VB.NET, remember
that the Exceptions are processed in order - they don't skip to the
corresponding handler .

HTH,

Bill

"smith flyers" <fl***@masfd.com> wrote in message
news:3f********@news.tm.net.my...
when using "try" can i use multiple "block catch" ? // i tried but

can't , this is allowed in java right, how about C#?
ex. catch(exception e) {} catch(FormatException){}
thank you for clarifying

Nov 15 '05 #2
In .NET, strings are immutable meaning that you cannot change their value.
All the operations on a string result in a new string. In this case,
String.Replace() returns a new string with the word "testing" replaced. You
can see it from this example where newValue contains the new string.

public static void Main()
{
string test="testing 1 2 3";
string newValule = test.Replace("testing", "test"); // why this doesn't
replace the word "testing" ?
}

Try using System.Text.StringBuilder instead, which does exactly what you
want:

public static void Main()
{
System.Text.StringBuilder sb = new StringBuilder("testing 1 2 3");
sb.Replace("testing", "test");
string newValue = sb.ToString();
}

Yes, you can have multiple catch blocks when using try. Here's an example:

public static void Main()
{
try
{
FileStream fs = File.Open(@"C:\Foo.txt", System.IO.FileMode.Open);
}
catch (ArgumentException e)
{
}
catch(FileNotFoundException e)
{
}
catch(IOException e)
{
}
finally
{
}
}

HabibH.

"smith flyers" <fl***@masfd.com> wrote in message
news:3f********@news.tm.net.my...
static void Main(string[] what) { string test="testing 1 2 3";
test.Replace("testing", "test"); } // why this doesn't replace the word "testing" ?

when using "try" can i use multiple "block catch" ? // i tried but can't , this is allowed in java right, how about C#?
ex. catch(exception e) {} catch(FormatException){}
thank you for clarifying

Nov 15 '05 #3

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

Similar topics

0
by: elein | last post by:
Can someone list susinctly the points of failure with using a file system snapshot solution to replicate a database for failover? If there is an...
1
by: UJ | last post by:
I've got a program that runs on a machine that will automatically update things like the DLLs that a group of programs use. I'm looking at using the...
8
by: ldndude | last post by:
Heya, I think I shot myself in the foot when I set this up Overview: I have a dynamically generated page for listing pictures for a project I am...
10
by: brooksr | last post by:
I know VB5/VBA very well but have not used VB to create web pages but need to do so. Can someone explain the purposes and differences between...
0
by: Marc Bartsch | last post by:
Hi, I have a WinForms application (C#, VS 2005) that consists of a treeview control and a notify icon. Below is a complete example of this...
5
hyperpau
by: hyperpau | last post by:
I just have some stupid questions but really want to know to fully understand vba more. What are the arguments for in some of the events? ...
13
by: poolboi | last post by:
hi guys, just wanted to find out something about cpan modules 'cos i'm still not sure what they are all about right...hm..first of all i did...
1
by: Ben white | last post by:
the CLR is .NET 2 not 1.1 (it pays to check facts)
6
by: Richard Penfold | last post by:
Can someone explain why a field on the many side of a one-to-many relationship, with referential integrity enforced, is not automatically updating? ...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.