|
I tried the following code, and it compiled without a problem:
string one = "abc-def";
string[] oneSplit = one.Split('-');
Next, I had this code, and compiler blew chunks:
string one = "abc-def";
string[] oneSplit = one.Split('-', 2);
But this compiled okay:
char[] sep = {'-'};
string one = "abc-def";
string[] oneSplit = one.Split(sep, 2);
Or do this (?):
string one = "abc-def";
string[] oneSplit = one.Split({'-'}, 2);
Does anyone know why?
-- modified at 18:02 Friday 21st September, 2007
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Sure, that's the params keyword for you in
public string[] Split (params char[] separator);
it tells the compiler one or more parameters (all of the same type) are to be
collected in an array automatically. And your 2 is not a char !
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Look at the available overloads. I was doing it right according to intellisense.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
No, there is no overload that takes just a char, they all take char arrays. Which, IMO, sucks.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
There is no overload that matches the second example. There is only one which has the params modifier which you use in the first example, all other overloads just have char[].
params can only be used for the last parameter in a method, they could have provided a string.Split(int count,params char[] separator) but they haven't.
|
|
|
|
|
Hi,
I'm trying to impersonate user identity between two WCF services (tcp.net).
When the client and the two services located on the same machine, everything work fine.
But when I move the services to a different machine than the client, it fails to pass the impersonated user identity to the second service (Client -> Server1 -> server2). I’m getting the following exception: “Either a required impersonation level was not provided, or the provided impersonation level is invalid”
Is it possible to do such a thing? what should be the configuration of the two servers?
|
|
|
|
|
Hi,
I would like to create a custom attribute for my C# application which will decorate methods. So far no problems. But I noticed that the attirbute constructor being called only when I reflecting the attribute parameters. I would like that the attribute's constructor will be called every time I enter the method (like when decorate a class with an attribute and its contructor being called when creating an instance of the class). How can I do this?
|
|
|
|
|
This isn't possible without getting into other concepts like PostSharp[^]
Attributes are intended to be evaluated at run time through reflection.
|
|
|
|
|
I'm looking for something similar to PrincipalPermission attribute.
So when I enter the method I'll be able to do a certain check (permissions check) and throw an exception if needed.
How does it implemented in PrincipalPermission?
|
|
|
|
|
You will need to do this yourself when you enter the method. You need to use reflection to see if the method has the attribute and take the appropriate steps if it does or doesn't.
The functionality you describe isn't implemented in the attribute at all. It is implemented by the calling method. Keep in mind that some of this behavior is intrinsic to the .NET runtime itself and checking security permissions like this should be part of the runtime function calling behavior.
|
|
|
|
|
I'm trying to set with filetype there are aloud to be when your are uploading.
I gett this errormessanger: CS1525: Invalid expression term '.'
The line thats error:
Line 10: string StrFileType = File1.PostedFile.ContentType(.JPG | .PNG)
The hole code:
void UploadFile(object Sender,EventArgs E)
{
if (File1.PostedFile !=null)
{
/
string StrFileName = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("\\") + 1) ;
string StrFileType = File1.PostedFile.ContentType(.JPG | .PNG) ;
int fileSize = (int)Math.Round((double)File1.PostedFile.ContentLength / 1024, 0);
int maxSize = 1024;
if (fileSize > maxSize)
Response.Write(" Uppladningen misslyckades! Storlek får högst vara 1mb ");
else
{
File1.PostedFile.SaveAs(Server.MapPath("img\\" + StrFileName));
lblUploadedFileName.Text ="Länken till bilden: http://domain.com/se/img/"+StrFileName;
lblbbcode.Text ="BBCode: [img]http://domain.com/se/img/"+StrFileName + "[/img]";
}
}
}
Frozzare, Segeltorps Scoutkår
www.segeltorps.scoutkar.nu
|
|
|
|
|
You might want to try putting quotes around the items in the ContentType. At the moment, the code looks as though it's a constant.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Then i get this errormesseanger:
CS0118: 'System.Web.HttpPostedFile.ContentType' is a 'property' but is used like a 'method'
Frozzare, Segeltorps Scoutkår
www.segeltorps.scoutkar.nu
|
|
|
|
|
It's bad karma getting you for posting a programming question in the lounge.
_____________________________________________
Flea Market! It's just like...it's just like...A MINI-MALL!
|
|
|
|
|
hi
String fileExt =
System.IO.Path.GetExtension(this.File1.FileName).ToLower();
ramana
|
|
|
|
|
I have a simple text box and a button when i click on a button the data must be saved to a table in sql how it can bedone
sas
|
|
|
|
|
|
SqlCommand myCommand = new SqlCommand("INSERT INTO Designation (Designation) " + "Values ('string')", myConnection);
the problem is in this line how to insert a text box value in the values place
sas
|
|
|
|
|
sajid.salim.khan wrote: SqlCommand myCommand = new SqlCommand("INSERT INTO Designation (Designation) " + "Values ('string')", myConnection);
the problem is in this line how to insert a text box value in the values place
What about myTextBox.Text? That'll give you the contents of the textbox.
It isn't enough to do well in life.
One must do good when and where one can.
Otherwise, what's the point?
|
|
|
|
|
i have done that but how to placeit in the value of mycommand parameter
SqlCommand myCommand = new SqlCommand("INSERT INTO Designation (Designation) " + "Values HERE ('string')", myConnection);
sas
|
|
|
|
|
programmer can learn only by googling around in MSDN or somethng like this. Dont, expect direct answer in CodeProject.Try somethings by yourself...
Regards
Chintan
www.visharadsoft.com
(I am thinking to change humans to computer, but unfortunately GOD will not give me the source code)
|
|
|
|
|
Anyone know how to do it? I need to figure out a way to run all of the unit tests under a specific namespace using C#.Net 2.0
--
"Keyboard not found. Press < F1 > to RESUME. "
Source unknown (appears in many common BIOSes as a real error message)
|
|
|
|
|
How to find a particular cell value in GridView RowUpdating event.
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e).
Please suggest.
Thanks
|
|
|
|
|
|
Hi,
I have a label and a tooltip associated with it.
If i hold the mouse over it and after a while the tooltip disappears.
string data = "hello world";
tip = new ToolTip();
tip.AutoPopDelay = 1500000;
tip.InitialDelay = 50;
tip.SetToolTip(this, data);
When i hold the mouse over the label again nothing is shown.
Is there a property or something to make it appear everytime i hold the mouse over
or shall i create the tooltip one more time?
Thanks!
|
|
|
|