|
Hi
Thanks you all your answers. I don't know why I couldn't think of this solution. Sometimes I can't think, and this is one of those times I guess.
|
|
|
|
|
int iCount = ("asdasd;asdasdasder;asdgfg;ad;;asdasd".Split(';')).Count<string>() - 1;
Well that gets it down to one line. What's next, obfuscation?
The true man wants two things: danger and play. For that reason he wants woman, as the most dangerous plaything.
|
|
|
|
|
Nice but,instead
Count() (which is not method) you have to use
Length int property
int iCount = ("asdasd;asdasdasder;asdgfg;ad;;asdasd".Split(';')).Length- 1;
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
and the cheapest approach probably is a.Length-a.Replace(";","").Length;
[CORRECTION]the single-line approach based on String.Replace is the most compact, however it is slower than an explicit loop checking every character, or looking for the next special character based on String.IndexOf; see my post below[/CORRECTION]
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
modified on Monday, June 8, 2009 1:29 PM
|
|
|
|
|
Is it? It would be making a new string, and the replace method that takes strings as arguments is extremely complicated.
|
|
|
|
|
Hi Harold,
I ran some tests (VS C# 2008, all release build), and the general conclusions are:
- optimum tactic depends on the data, mostly on the fraction of special characters (';') present;
- with lots of ';' the explicit loops are better;
- with few or no ';' string methods are better;
- my single-line approach based on string.Replace never wins;
- when string.Length is present in the for statement, it consumes >30% of the CPU cycles;
- with fewer than 15% of special chars, the winner is IndexOf (see below); for extemely long strings it is up to 4 times faster than the second fastest (explicit loop without Length in for statement).
int n=0;
int start=0;
for (; ; ) {
int j=test.IndexOf(';', start);
if (j<0) break;
n++;
start=j+1;
}
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Cool good to know!
Instant 5
|
|
|
|
|
Hi all,
i have 1 project to create dll for foxpro apps to call.
now i need to create 2 line of line chart but it wont work. now it just show 1 line.
//Line
LineItem lineItemCurve = graphPaneChart.AddCurve(null, null, null, Color.Aqua, SymbolType.Circle);
LineItem lineItemCurve2 = graphPaneChart.AddCurve(null, null, null, Color.Red, SymbolType.Diamond);
foreach (double[] daDashboardCharInfo in dashboardChartInfo.ValueSet)
{
lineItemCurve = graphPaneChart.AddCurve(dashboardChartInfo.ValueSetTitle, null, daDashboardCharInfo, Color.Aqua, SymbolType.Circle);
lineItemCurve2 = graphPaneChart.AddCurve(dashboardChartInfo.ValueSetTitle, null, daDashboardCharInfo, Color.Red, SymbolType.Diamond);
}
lineItemCurve.Symbol.Fill = new Fill(Color.Aqua);
lineItemCurve.Symbol.Size = 6;
lineItemCurve.Line.Width = 1.2F;
lineItemCurve2.Symbol.Fill = new Fill(Color.Red);
lineItemCurve2.Symbol.Size = 6;
lineItemCurve2.Line.Width = 1.2F;
Thanks.
|
|
|
|
|
Hi there,
I want to add dynamically checkboxes to the datagridview rows which displays data on textchange event of a textbox.
On clicking checkboxes I want to go for further coding.
Please help.
|
|
|
|
|
Hi,
from the dategridview, you can select edit columns and click "add" and for columntype just select
"DataGridViewCheckBoxColumn".
HTH,
Jeff.
|
|
|
|
|
Hi,
Sir,You just suggested me the solution at design time. But here I m displaying data from database dynamically on textchange event using like query in datagrid.
|
|
|
|
|
Hello All,
I am getting the following exception when I run my C# application. I am using VS2008 and I am logged into my computer as admin. I have also launched VS2008 with admin permissions. I am using WinXP SP2 and Spring .NET version . Can someone help ?
*********************************************************************************************************************
System.Configuration.ConfigurationErrorsException was unhandled by user code
Message="Error creating context 'spring.root': Request for the permission of type 'System.Configuration.ConfigurationPermission, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed."
Source="Spring.Core"
BareMessage="Error creating context 'spring.root': Request for the permission of type 'System.Configuration.ConfigurationPermission, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed."
Line=0
StackTrace:
at Spring.Context.Support.ContextHandler.Create(Object parent, Object configContext, XmlNode section) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Context\Support\ContextHandler.cs:line 291
at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSection(Boolean inputIsTrusted, RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
at System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
at System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader, String filename, Int32 line)
InnerException: Spring.Util.FatalReflectionException
Message="Cannot instantiate Type [Spring.Context.Support.XmlApplicationContext] using ctor [Void .ctor(System.String, Boolean, System.String[])] : 'Exception has been thrown by the target of an invocation.'"
Source="Spring.Core"
StackTrace:
at Spring.Util.ObjectUtils.InstantiateType(ConstructorInfo constructor, Object[] arguments) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Util\ObjectUtils.cs:line 254
at Spring.Context.Support.ContextHandler.RootContextInstantiator.InvokeContextConstructor(ConstructorInfo ctor) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Context\Support\ContextHandler.cs:line 549
at Spring.Context.Support.ContextHandler.ContextInstantiator.InstantiateContext() in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Context\Support\ContextHandler.cs:line 493
at Spring.Context.Support.ContextHandler.InstantiateContext(IApplicationContext parentContext, Object configContext, String contextName, Type contextType, Boolean caseSensitive, String[] resources) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Context\Support\ContextHandler.cs:line 336
at Spring.Context.Support.ContextHandler.Create(Object parent, Object configContext, XmlNode section) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Context\Support\ContextHandler.cs:line 279
InnerException: System.Reflection.TargetInvocationException
Message="Exception has been thrown by the target of an invocation."
Source="mscorlib"
StackTrace:
at System.RuntimeMethodHandle._InvokeConstructor(Object[] args, SignatureStruct& signature, IntPtr declaringType)
at System.RuntimeMethodHandle.InvokeConstructor(Object[] args, SignatureStruct signature, RuntimeTypeHandle declaringType)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
at Spring.Util.ObjectUtils.InstantiateType(ConstructorInfo constructor, Object[] arguments) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Util\ObjectUtils.cs:line 249
InnerException: Spring.Objects.Factory.ObjectDefinitionStoreException
Message="Could not resolve resource location [config://spring/objects]"
Source="Spring.Core"
ObjectName=""
ResourceDescription=""
StackTrace:
at Spring.Objects.Factory.Support.AbstractObjectDefinitionReader.LoadObjectDefinitions(String location) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectDefinitionReader.cs:line 229
at Spring.Objects.Factory.Support.AbstractObjectDefinitionReader.LoadObjectDefinitions(String[] locations) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectDefinitionReader.cs:line 255
at Spring.Context.Support.AbstractXmlApplicationContext.LoadObjectDefinitions(XmlObjectDefinitionReader objectDefinitionReader) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Context\Support\AbstractXmlApplicationContext.cs:line 214
at Spring.Context.Support.AbstractXmlApplicationContext.LoadObjectDefinitions(DefaultListableObjectFactory objectFactory) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Context\Support\AbstractXmlApplicationContext.cs:line 238
at Spring.Context.Support.AbstractXmlApplicationContext.RefreshObjectFactory() in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Context\Support\AbstractXmlApplicationContext.cs:line 133
at Spring.Context.Support.AbstractApplicationContext.Refresh() in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Context\Support\AbstractApplicationContext.cs:line 764
at Spring.Context.Support.XmlApplicationContext..ctor(Boolean refresh, String name, Boolean caseSensitive, IApplicationContext parentContext, String[] configurationLocations) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Context\Support\XmlApplicationContext.cs:line 217
at Spring.Context.Support.XmlApplicationContext..ctor(String name, Boolean caseSensitive, String[] configurationLocations) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Context\Support\XmlApplicationContext.cs:line 122
InnerException: System.Security.SecurityException
Message="Request for ConfigurationPermission failed while attempting to access configuration section 'spring/objects'. To allow all callers to access the data for this section, set section attribute 'requirePermission' equal 'false' in the configuration file where this section is declared."
Source="System.Configuration"
StackTrace:
at System.Configuration.BaseConfigurationRecord.CheckPermissionAllowed(String configKey, Boolean requirePermission, Boolean isTrustedWithoutAptca)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at Spring.Util.ConfigurationUtils.GetSection(String sectionName) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Util\ConfigurationUtils.cs:line 58
at Spring.Core.IO.ConfigSectionResource..ctor(String resourceName) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Core\IO\ConfigSectionResource.cs:line 89
at Spring.DynamicReflection.Ctor_ConfigSectionResource_c47035f20d0b4f8f86335dc74e27af5e.Invoke(Object[] args)
at Spring.Core.IO.ConfigurableResourceLoader.GetResource(String resourceName) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Core\IO\ConfigurableResourceLoader.cs:line 149
at Spring.Objects.Factory.Support.AbstractObjectDefinitionReader.LoadObjectDefinitions(String location) in l:\projects\spring-net\trunk\src\Spring\Spring.Core\Objects\Factory\Support\AbstractObjectDefinitionReader.cs:line 226
InnerException: System.Security.SecurityException
Message="Request for the permission of type 'System.Configuration.ConfigurationPermission, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed."
Source="mscorlib"
StackTrace:
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.Configuration.BaseConfigurationRecord.CheckPermissionAllowed(String configKey, Boolean requirePermission, Boolean isTrustedWithoutAptca)
InnerException:
*********************************************************************************************************************
Thanks,
Ashwanth
|
|
|
|
|
Sounds like some nasty code access security thing to me. Did you notice that buried in the middle of the stack trace these words:
Message="Request for ConfigurationPermission failed while attempting to access configuration section 'spring/objects'. To allow all callers to access the data for this section, set section attribute 'requirePermission' equal 'false' in the configuration file where this section is declared."
Source="System.Configuration"
Have you done that?
Regards,
Rob Philpott.
|
|
|
|
|
I had the requirePermission attribute already set to false. It has not helped.
Thanks,
Ashwanth
|
|
|
|
|
How to get a webbrowser control of IE? When a user clicks on back button of top left corner of IE window, how can I know, Is any event fired?
|
|
|
|
|
|
Dear All,
well i want to make my own panel like an expander which can be expanded and collapased.
this expand and collapse is done by a button, I have made this control which works in run time.
i want expand and collapse functionality in design time, means when we add that control to my panel, i should be able to collapse and expand it.
in run time i have done it, i also add several events to my controls, but still i am lacking to add expand and collapse functionality in design time.
I do really appreciate your idea?
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
You can start by reading this[^]. It's a good intro to design time features in custom controls.
Simon
|
|
|
|
|
Simon, thanks alot.
I have read the topic, infact it did not solved my problem, but i have learned other issues and mostly how to add smart tag from to control at design time.
still i am looking for a method to add design time event for my control, i have seen several posts in regarding such issue,but the links were down.
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
How do I set TXA-2 to "Counselling System^^DOC"?
My current code can only give "Counselling System" output.
((TXA)msg.GetStructure("TXA")).DocumentType.Value = "Counselling System";
Is there a way to set "DOC" to TXA-2-3 using NHapi?
Thank you in advance.
|
|
|
|
|
Found a solution.
I used Terser to set the value.
Terser terser = new Terser(msg);
terser.Set("/.TXA-2-3", "DOC");
|
|
|
|
|
Thank you, It's worked for me
|
|
|
|
|
Hi,
First time I am doing programming with datagridview. I read from net and various sites that it is very powerful to show data.
I have some question and want suggestion and tips or if possible some demo programming help.
1. Want grid should be for insert, update, delete with validation.
2. My data source is a mix table query means join of two or more table.
3. want columns as autocompletemode.
4. unique rows in grid some key values must be not in repeat
please help me
Regards
Prakash Paul
Prakash
|
|
|
|
|
Hi,
(i) Use Edit Item Template to update the grid.
(ii) Your data source may contain values from multiple tables, but that won't create any problem as you can simply put those values into a datatable and bind the data table to the data grid vew.
(iii) Use AJAXAutoCompleteExtender control in the row data bound event of the data grid view. You need to use it dynamically.
(iv) you have to check it in your query and ensure that only distinct rows come into the result set.
Regards
Saanj
Either you love IT or leave IT...
|
|
|
|
|
Using c#, how can I catch the onclick event when a user clicks on "BACK" button on top left corner of Internet Explorer window, I want to do this using a BHO...
|
|
|
|
|