|
My input is
Deep Well, landscape [1,1]
and I need to parse at the comma so I will have "deep well" as 'WellType' and then after the space so that "landscape" will be 'WellOrientation'. Sounds easy. The catch is sometimes 'WellType' will have a space, and other times it will not. Also, Orientation can be all kinds of things not just landscape. And the [1,1] is fine no issues with that.
My current expression is
(?'WellType'[^,]*)\s(?'WellOrientation'[^\s])
And this my output is:
WellType: Deep
WellOrientation: W
Now Im pretty sure i know the problem, which is a first for me. [^,]* is saying keep going until you reach a comma, but then i have \s, which says stop at the space. Because the input has both a comma and a space im getting this output.
any ideas on how to get this working?
|
|
|
|
|
How about this:
(?'WellType'[^,]*),\s(?'WellOrientation'[^\s]*)
^ ^
|
|
|
|
|
|
|
(?'WellType'\w*),\s(?'WellOrientation'\w)
should also work
a programmer traped in a thugs body
|
|
|
|
|
No, it doesn't, because of the whitespace. You also left off the second asterisk.
But "(?'WellType'.*),\s(?'WellOrientation'.*)" does.
|
|
|
|
|
Hello,
I have written a C# console-application that depends on a number of environment variables. These variables are set in a *.bat file.
I would like to run that file and have the variables set in my application's environment.
Unfortunatly that doesn't work, a least not by using System.Diagnostics.Process.
Am I missing something? Any Idea?
Thanks for any help.
|
|
|
|
|
Try using the System.Environment class. It has several static methods that should help solve your problem.
|
|
|
|
|
I know System.Environment.
It allows me (among other things) to set and retrieve enviroment variables.
But I need to use the *.bat file because it is not under my control and I don't otherwise know the values it will set.
|
|
|
|
|
Won't the BAT file run in its own process and only affect that process?
|
|
|
|
|
Yes. That's exactly my problem.
How can I either:
1.) Access the environment of that (finished!) process?
-- or --
2.) Make another process acces the environment of my process?
BTW: System.Diagnostics.ProcessStartInfo.EnvironmentVariables is of no help here.
|
|
|
|
|
|
Me too! That's why I asked
|
|
|
|
|
The workaround I use now is calling something like:
cmd.exe /c "call settings.bat > nul & set"
and parse the output (of the 'set' command).
UGLY!
Any better solution will be more than welcome.
|
|
|
|
|
Then why not just read an XML document?
|
|
|
|
|
Hi,
When I am executing the .net web applicaiton I get this error randomly. I mostly get it first time I start the application buy hitting F5. It ususally works second time. However, the execution might throw the same error when running the application second time as well.
FYI:I have C# web application
I see following message on the .net solution:
Disassembly cannot be displayed. The expression has not yet been translated to native machine code.
On the page side, I see
Internet Explorer cannot display the webpage
This problem can be caused by a variety of issues, including:
•Internet connectivity has been lost.
•The website is temporarily unavailable.
•The Domain Name Server (DNS) is not reachable.
•The Domain Name Server (DNS) does not have a listing for the website's domain.
•There might be a typing error in the address.
•If this is an HTTPS (secure) address, click Tools, click Internet Options, click Advanced, and check to be sure the SSL and TLS protocols are enabled under the security section.
Thanks
Needy
|
|
|
|
|
Turn off "Show friendly HTTP error messages" in IE.
Turn off "Enable address-level debugging" in Visual Studio
Try again :P
|
|
|
|
|
Hi
i want to insert multiple rows to database in a single transaction via TransactionScope class, for this, i iterate through datatable that binds to datagridview for get list of rows to be inserted. here is my code :
using (SqlConnection con = new SqlConnection("data source=.;initial catalog=test;Trusted_Connection=Yes"))
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "insert Person(titleId,fname,lname) values(@titleId,@fname,@lname)";
con.Open();
System.Transactions.TransactionOptions trOptions = new System.Transactions.TransactionOptions();
trOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
trOptions.Timeout = new TimeSpan(0, 0, 15);
using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, trOptions))
{
try
{
foreach (DataRow row in this.dt1.Rows)
{
int titleId = int.Parse(row["titleId"].ToString());
string fname = row["fname"].ToString();
string lname = row["lname"].ToString();
if (cmd.Parameters.Count > 0)
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@titleId", titleId);
cmd.Parameters.AddWithValue("@fname", fname);
cmd.Parameters.AddWithValue("@lname", lname);
cmd.ExecuteNonQuery();
}
con.Close();
ts.Complete();
}
catch (Exception ex)
{
}
}
}
but when any error occur during foreach loop (insert loop), those rows that inserted to database, could not rollback.
where does my problem and how to solve it ?
Note : i know this can implement by SqlTransaction, but i want to do with TransactionScope class.
Thanks
|
|
|
|
|
Wrap your TransactionScope around the entire thing. ADO.NET will autoenroll in a System.Transaction if one is in scope, but only if it is created within that scope. The way your example is written, you are creating your transaction after you create your command and connection...I don't think auto-enrollment is possible in that scenario.
using (TransactionScope scope = new TransactionScope())
{
using (SqlConnection con = new SqlConnection(...))
{
using (SqlCommand cmd = new con.CreateCommand())
{
}
}
}
|
|
|
|
|
Hi there
I'm just beginning to get my head around C#, having moved from a background in C/C++, Java, and (a long time ago) Pascal.
I'm writing a program in which I have declared a series of classes that model the data layer and which, as in this layer I'm working with .xml, the class names reflect the schema of that layer, with names like ...Node and ...ChildNode and the like. As I now move up to the business model layer, I'd like to recast these type names to others more suitable to that model. For example, instead of XMLProjectNode I'd like to just use Project.
I'm experimenting with aliases and using things like:
using Project = My.Namespace.XMLProjectNode;
but what I'd like to be able to do is declare these aliases somewhere in a once-for-all location so that they can be imported into any module for immediate use without the need for redefinition.
In C++ I would put some #defines in a header file and #include it wherever I needed them. However, I can't seem to find an analogous way to do that in C#.
Am I missing something, or is this not possible?
Many thanks
BS
|
|
|
|
|
It's not possible I'm afraid. You could always create a snippet with these defined and drag them in when you need them.
Cancel my answer. PIEBALDconsult is a coding god here - go with what he said.
|
|
|
|
|
Sure it is. Perhaps not advisable, and not a good fit in this situation, but possible.
|
|
|
|
|
Please expand. Based on my reading of the OP, he was asking if it was possible to store using statements in one location and then reuse them in other locations just by referring to this single location.
|
|
|
|
|
Of course, just as in C like he asked:
C:\>type test.h
using System ;
C:\>type test.cs
# include "test.h"
namespace Template
{
public static class Template
{
[STAThreadAttribute()]
public static void
Main
(
)
{
Console.WriteLine ( "It works" ) ;
}
}
}
C:\>"C:\Program files\mingw\bin\cpp" -P -C -w test.cs test.csi
C:\>csc test.csi
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.1
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.
C:\>test
It works
C:\>
|
|
|
|
|
Well blow me sideways with a plastic marionette. I've just learned something new - and if I could award you a 100 for that post I would. Way to go you keyboard lovegod you.
|
|
|
|