Posts

Showing posts from September, 2011

Donate

Manipulate Object Property Using Lambda Expression In LINQ

Here's how to manipulate or update an object property using Lambda format in LINQ. In this example, I assigned a value to the textbox control's Text property using a delegate that applies the concept of Lambda expressions in LINQ. ShowEmployeeDelegate d = () => { tMessage.Text = "Nelson" ; }; d.Invoke();

Remove Open And Close Square Brackets In A Sentence Using Regular Expression In C#

Given the sample string data [Posted Friday September 23 2011] and you need format the sentence like this Posted Friday September 23 2011 without the square brackets, a solution would be to use Regex. string date = Regex.Replace(date, "[\\[\\]]" , string .Empty); date = Regex.Replace(date, @"[\[\]]" , string .Empty);

Replace Character In A String Based On Specific Index In C#

Here's an example snippet that will replace a character based from a specific index. Source: DreamInCode To use it in your program do it like this: // Replaces a character in a string with the character specified. void replaceCharWithChar( ref string text, int index, char charToUse) { char [] tmpBuffer = text.ToCharArray(); buffer[index] = charToUse; text = new string (tmpBuffer); } //IN YOUR MAIN MODULE/FUNCTION. //money has comma, example: $2,000, 4 BR, 180 m² //LandPriceBedroom = "$120, 2 BR, 90 m²"; //IF COMMA OCCURS MORE THAN TWO, REPLACE THE FIRST //COMMA WITH SPACE. SINCE IT COULD BE A MONEY W/ //THOUSANDS SEPARATOR if (LandPriceBedroom.Split( ',' ).Length > 3) { int firstIndexComma = LandPriceBedroom.IndexOf( "," ); replaceCharWithChar( ref LandPriceBedroom, firstIndexComma, ' ' ); }

Regular Expression Remove String With A Punctuation Beside It In A Sentence In C#

Assuming in a sentence, you want to remove the word apply now in any case. This word has a punctuation beside it. Example: Apply now! Apply now. APPLY NOW! APPLY NOW. apply Now! apply Now. In a sentence: We are in need of VB.NET Developers. Apply Now! We are in need of VB.NET Developers. Apply now! We are in need of VB.NET Developers. APPLY NOW! We are in need of VB.NET Developers. apply now! To remove, just use the code below: description = Regex.Replace(description, "apply now[!.]" , string .Empty,RegexOptions.IgnoreCase).Trim(); Note: I'm not a Regex expert.

Remove Dotted Lines Or Whitespaces In Visual Studio 2010

Good evening gents! Use the shortcut keys below to remove the dotted lines or white spaces in your Visual Studio 2010 IDE: 1. ctrl r+w or 2. ctrl e+s Cheers!

Uncompress GZip Response Using WebClient In C#

In a scenario where you want to download xml data using webclient, the response from firefox or any browser will display the xml file correctly. However, using a web request/webclient.downloadstring to download the xml file, the response is somewhat corrupted or in hashed form. The response headers are the following: 1. Content-Type - application/xml 2. Content-Encoding - gzip As you can see, the content encoding is of type gzip . The solution is to override the web request method to something like this: class DecompressGzipResponse : WebClient { protected override WebRequest GetWebRequest (Uri address) { HttpWebRequest request = (HttpWebRequest) base .GetWebRequest(address); request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; return request; } } //to use this in the program (main function) DecompressGzipResponse client = new DecompressGzipResponse (); Listi...

How To Convert Exponent to Decimal Notation In C#

Good morning, Here's how you convert exponent value to C# using decimal.parse() function. Make sure to pass NumberStyles.Float from System.Globalization namesapce in the second parameter of the function. string land_area = "1.21445e-007" .ToUpper(); decimal dec = decimal .Parse(land_area, System.Globalization.NumberStyles.Float);

How To Count Number Of Character Or ElementOccurrences In A String Using C#

Hello All, In order to count the occurences of a certain element or character in a string, you need to perform the split() function and subtract the length with one to get the actual count. int count_li = tempListSource.Split( new string []{ "<li>" }, StringSplitOptions.RemoveEmptyEntries).Length - 1;

Reset Seed In MySQL Table

To reset the seed of a MySQL table, perform alter table statement and set the AUTO_INCREMENT value to 1. ALTER TABLE tblProduct AUTO_INCREMENT = 1; Cheers!

Donate