|
|
.Substring ?
haripinna wrote: pick a single letter and the position from that string
if you mean "and get the position", then try .IndexOf
modified on Saturday, May 17, 2008 11:16 AM
|
|
|
|
|
Thanks for giving response.
i can't get you..
please provide code for that..
Thnaks,
Pinna
Pinna
|
|
|
|
|
Did you search for Substring? It's a method which you can use on any string - look in MSDN
TextBox1.Text.Substring(i, l);
will retrieve the number of characters specified by l from the position specified by i .
Dave
|
|
|
|
|
Or Use .CharAt
Thanks
"Good Thing Goes With Good People..."
|
|
|
|
|
Not sure what you mean by "pick". If you mean "find", see the IndexOf() [^] method.
/ravi
|
|
|
|
|
Hi, I have several servers which have an Intel Pro network adapter with several vlans. I am attempting to write a C# application to modify the vlan id and vlan name for a single adapter. I've been able to query the id's and names via WMI, however when i attempt to use a PUT() (update only) i receive a generic error. Reading the documentation it says i need to do a putinstance() for those values. I've managed to find a C++ version of PutInstance() but nothing for C#. Any assistance on how i can do this with native C# classes? Thanks!
|
|
|
|
|
Maybe this[^] helps.
SkyWalker
|
|
|
|
|
I want to corp a rectangular region from a Bitmap. when i corp i dnt get the exact region corped. the resultant image is not exactly whaT I SELECTED!.
I tried the fillowing code:
BitmapData bmpdata = ParentImage.LockBits(rect, ImageLockMode.ReadWrite , PixelFormat.Format24bppRgb);
Bitmap Corped = new Bitmap(bmpdata.Width, bmpdata.Height, bmpdata.Stride, PixelFormat.Format24bppRgb, bmpdata.Scan0);
where rect is the rectangular object that represents my selection.
(Jameel)
|
|
|
|
|
Corped? Do you mean croped?
I wouldn't bother locking the bits and doing it that way, i would just use GDI+ to draw to a new bitmap, like this:
Bitmap image = ...;
Bitmap newImage = new Bitmap(rect.Width, rect.Height);
Graphics g = Graphics.FromBitmap(newImage);
Rectangle destRect = new Rectangle(0,0, rect.Width, rect.Height);
g.DrawImage(image, destRect, rect, GraphicsUnit.Pixel);
g.Dispose();
then newImage should contain what you want, unless of course your setting your rectangle wrong.
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
I want to get the email form my Outlook addressbook. Now, I can only get the name. I have no idea, how I can get email.
Outlook.AddressList addressList;
for (int i = 3; i <= addressLists.Count; i++ )
{
addressList = addressLists[i];
Console.WriteLine("Name: {0}", addressList.Name);
Outlook.AddressEntries addressEntries = addressList.AddressEntries;
foreach (Outlook.AddressEntry addressEntry in addressList.AddressEntries)
{
Console.WriteLine("{0}", addressEntry.Name);
Console.WriteLine("{0}", addressEntry.Address);
addressEntry
}
}
|
|
|
|
|
Hello everyone,
I want to iterator a Dictionary variable instance, and remove all elements under a specific condition.
Here is my code. My questions about whether the following solution will function correctly?
1. will dic.Remove(key) operation impact keys collection?
2. will dic.Remove(key) operation impact dic[key] operation?
I have such concern is because I heard while interation in the middle, remove any elements inside the Dictionary is dangerous because it will make some reference invalid and impact result. Any ideas?
Dictionary<string, Foo>.KeyCollection keys = dic.Keys;
foreach (string key in keys)
{
if (dic[key].order > 100)
{
dic.Remove(key);
}
}
thanks in advance,
George
|
|
|
|
|
No, you may not alter the contents of a collection while foreach ing it.
|
|
|
|
|
Thanks PIEBALDconsult,
Could you provide some pseudo code which could iterate all elements in a Dictionary and remove the ones under specific condition please?
regards,
George
|
|
|
|
|
Well, judging by your other post, if you want to remove a bunch of entries and reduce the footprint, then copying the items you want from one to a new one ought to be the way to go.
Another way would be to foreach the Dictionary, adding the-keys-you-want-to-remove to a List, then foreach the List removing the entries from the Dictionary.
Or, use .Keys.CopyTo to copy the keys to an array, for the array, and do the tests and removals.
|
|
|
|
|
Thanks PIEBALDconsult,
Keys.CopyTo will copy all the keys elements themselves' value, not only just copy a reference?
regards,
George
|
|
|
|
|
Correct, it will copy each of the keys.
|
|
|
|
|
Thanks PIEBALDconsult,
1.
I agree with your solution. I have a further question, why my code dic.Remove(key) will invalid the loop foreach (string key in keys)? How Dictinoary is designed which will be impacted?
2.
I have read the related document for CopyTo,
http://msdn.microsoft.com/en-us/library/91e2z0hz(VS.80).aspx[^]
I am interested to make some test program to verify the actual value is make a copy, not just the reference, any ideas about how to test?
regards,
George
|
|
|
|
|
1) That's the nature of the beast.
2) Why bother?
|
|
|
|
|
Thanks PIEBALDconsult,
I am interested to learn how Dictionary is designed so that when remove one element, foreach loop will become invalid. Any ideas?
regards,
George
|
|
|
|
|
No, it just is, move along.
|
|
|
|
|
Thanks PIEBALDconsult,
I am interested to know some internals about how Dictionary is implemented. If you have any good resources or documents, please feel free to share with us here.
I think most people are using Dictionary frequently and must be interested.
regards,
George
|
|
|
|
|
If you remove an item from the dictionary, that will invalidate the enumerator that the foreach command is using, so it's not possible to remove items in a loop like that.
Do like this:
List<string> remove = new List<string>();
foreach (KeyValuePair<sting, foo=""> item in dic) if (item.Value.order > 100) remove.Add(item.Key);
foreach (string key in remove) dic.Remove(key);</sting,>
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks Guffa!
Cool!
In my original code, I am not foreach the whole Dictionary, just the .Keys of the Dictionary (i.e. using Keys Enumerator, not using Dictionary as a whole Enumerator). In this case, deleting an element will also invaliding the Keys Enumerator? Why?
(Does it because .Keys operations on the Dictionary will prefetch all the pointers to old positions before element removal?)
regards,
George
|
|
|
|
|
George_George wrote: In my original code, I am not foreach the whole Dictionary, just the .Keys of the Dictionary (i.e. using Keys Enumerator, not using Dictionary as a whole Enumerator). In this case, deleting an element will also invaliding the Keys Enumerator? Why?
Because the key collection doesn't exist separately. It reads from the dictionary when you loop through the keys.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|