|
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
I will answer this if you post it in the Regular Expressions forum.
|
|
|
|
|
I don't see a "regex forum? anywhere
Everything makes sense in someone's mind
|
|
|
|
|
On the left hand side of your screen, labelled "Regular Expressions".
There is a short cut here[^]
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Ahh, found it.. Thanks
Everything makes sense in someone's mind
|
|
|
|
|
"(BR108)|(CC129)"
although why use a regex in that case? just do two string compares.
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|
|
Probably because the regex will still work if there is other info in the string:
Shipment ID: 212857,1212,Invoice No: BR108, 25-JAN-10 (PDF) Would match as a Regex, but it could take two String.Contains method calls to check for either substring.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
ah, yes, good point
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|
|
You didn't give the OP a chance to post in the Regex forum.
And you didn't obfuscate that regex enough:
^(?![Bb][Rr]12|[Cc]{2,2}10|trogdor)([Bb][Rr]|[Cc]{2})1(08|29)$
There, much better.
|
|
|
|
|
lol,
i looked in the regex forum for his post, but he didn't post there so i answered here.
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|
|
Thats right, you start off with one problem and introduce a Regex expression and now you have two problems.
Architecture is extensible, code is minimal.
|
|
|
|
|
Hi all,
Is there an equivalent of the stl::vector<>.reserve() function for .NET Collections?
I'm building a large menu dynamically and it's a slow process and I either need to speed it up (hence my question) or do it all a different way.
|
|
|
|
|
Remember C# is managed code, the whole notion is to free you up from allocation/deallocating.
Which .NET collection class are you using? May be if you post your code snippets it may be helpful understanding as to what is going on on your code.
|
|
|
|
|
Generic collections offer at least one constructor that takes an initial capacity; having said that, I don't believe it is the growth of the collection itself that causes a noticeable slowdown. Telling more about your app, maybe showing some relevant code, would enable people to give some specific advice.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Luc Pattyn wrote: Generic collections offer at least one constructor that takes an initial capacity
Thanks Luc, I'd missed that one. I was dynamically filling a ContextMenuStrip from an XML file that had over 400 entries each in two submenus, but I've changed it to use statically filled ToolStripComboBox es instead and it starts immediately.
|
|
|
|
|
You're welcome.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Collections such as List<T> (starting with a default capacity of 4) double their capacity once filled...
List<int> list = new List<int>();
Console.WriteLine(list.Capacity);
list.Add(0);
Console.WriteLine(list.Capacity);
list.AddRange(new int[] { 1, 2, 3, 4 });
Console.WriteLine(list.Capacity);
list.AddRange(new int[] { 5, 6, 7, 8 });
Console.WriteLine(list.Capacity);
list.AddRange(new int[] { 9, 10, 11, 12, 13, 14, 15, 16 });
Console.WriteLine(list.Capacity);
I believe they do this by allocating a new area in memory big enough to create the wrapped inner array with the new capacity then copying the existing elements to the new array. If these are large collections then that could be the source of the slowness, but unlikely unless the collection is having to resize many times.
You can avoid the new memory allocation and copying by specifying a suitable capacity for the collection in the constructor...
List<int> list = new List<int>(DesiredCapacity);
|
|
|
|
|
I stumbled upon a little article here[^] that seems to confirm what you said.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Wow, that author is brilliant! So is this one!
|
|
|
|
|
Some things you can try:
- Set the intial capacity of the list as large or larger than you think you'll need it (as others have mentioned, the List class has a constructor for this purpose). This could potentially cut the time in about half.
- Use structs rather than classes so the memory will be allocated immediately rather than in small chunks over time.
- Recycle your objects (that is, don't make new objects... save them for use later).
|
|
|
|
|
Hi,
I want to generate from an PDF Images.
But how??
My favorite iTextSharp.
thx
|
|
|
|
|
|
Thanks Yusuf!
I now... but i can´t find a exampel (iTextSharp) to gernerate thumbnails
In IText NOT in ITextSharp can i use this function: decoder.getPageAsImage(PageNumber)
But how can i create thumbnails with iTextSharp???
thx!!!
|
|
|
|
|
I don't know as I never worked with iTextSharp.
We use imagemagick[^] and GhostScript[^] to generate thumbnails of PDF files. But that is completely different way of doing it.
Is there something you can make use in here[^]?
|
|
|
|
|
I am trying to write code so that if the local admins are not certain predefined accounts or groups, then they are removed.
The closest I have gotten is the code below, but it stops at the children.Remove(badObject) line and fails saying it isn't the correct format. Can anyone help please?
string userName = "WinNT://computername/test12";
userName = userName.Substring(userName.Length - 6);
DirectoryEntry de = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
DirectoryEntries children = de.Children;
DirectoryEntry badObject = children.Find("userName");
children.Remove(badObject);
de.CommitChanges();
|
|
|
|