Andrew Pallant

Software and Web Developer


Follow MadProgrammer on Twitter

View Andrew Pallant's profile on LinkedIn

Friday, April 17, 2009

 

How would you split with C#?

How would you split a string with comma separated values and remove any blank records?

While the solution may seem obvious to most folks, it is not always obvious to everyone. I have been asking perspective candidates this question, but there is one common answer that I get.

"Create a loop with two array variables. Loop through the comma separated string and do substring to extract each value while keeping the current index to use as your next starting point. Then create another loop to loop through your new array of strings to add the strings with length greater than zero to a new array... then return your newest array of strings."

That seems like a lot of loops, a lot of string arrays and a lot of thinking.

Whenever I suggest using the String object's split command using the RemoveEmptyEntries; I get told "Oh, what I told you is probably what DotNet is doing under the hood".

My god, that seems like a lot of work even for DotNet. I urge everyone to look at the functions available before undertaking such routines. Can you imagine the code that would be produced by a developer who is always writing code like described above? If you are unsure, use google to find your answer or even better yet use MSDN. Do not assume you know everything, because you are not expected to. There are resources around... Internet is a developer's best friend.

Source for String Split Options: http://msdn.microsoft.com/en-us/library/ms131448.aspx

Sample Google Query used to find the answers:

Tuesday, April 7, 2009

 

Seven Tips to Project Success


  1. Before starting any project, you should know what you are doing before you start. Ask your users, create focus groups and research every detail. By asking your users you will know what your users will need to do their jobs and what they are expecting. Focus groups will provide feed back of what direction you should be taking the project by telling you what they think will work or not work. Both users and focus groups should be used through out the project in order to keep the project on track. Lastly, research your project to ensure you have all of the information and regulations written down so that all can review, understand and agree. Know every bit of your project.


  2. After done your research and you have talked to the users, it is time to formalize a project plan. First outline all requirements of the projects so that all parties can understand. You should include charts, graphs and diagrams where applicable. Now, add to your formal project plan a break down the individual pieces into tasks, people resources and time to complete each task. By now you should really know what you need to complete the project
    and it is time to list anything that need to complete the tasks outlines, concerns that you have for doing the project and any other special notes.

  3. Sit down with all stakeholders of the project including users and management and discuss the formal project plan. Ensure everyone understands the pan, what it will take to do the plan and that anything new will move the timeline out. Get management to sign-off on the plan indicating the understand and agree with everything.

  4. Do not stop using the users and focus groups, they will ensure you stay on task and that you are not going off on the wrong track. They will discover issues before the project is done. Do not get defensive when the discover issues.

  5. Follow-up with your people resources on a weekly basis to ensure that they are still on task. Encourage them to come to you sooner than later with issues.

  6. Test, Test, Test

  7. Deliver the final project to management and users by doing a proper presentation, training and sign-off sessions. Without proper training and presentations you will have user errors and a very busy support desk. If this is a contract project ensure that your company that you are working for know the terms of support and training. Sign-off sessions is just a indication that you are done as per your plan which was also signed off.


 

Javascript equalsIgnoreCase Function

This week's code sample is JAVASCRIPT based. I found this while researching user validation routines. This function is a javascript version of a common Java function. We have replicated the calling syntax as a java programmer would expect to use it by effectively appending it as a method of the javascript String Object.

For more great scripts: http://www.apriori-it.co.uk

Important Note: Works with IE and FireFox

  
//The first line assigns the MatchIgnoreCase function as
//an equalsIgnoreCase method of the String object
String.prototype.equalsIgnoreCase=MatchIgnoreCase;

function MatchIgnoreCase(strTerm, strToSearch)
{
strToSearch = strToSearch.toLowerCase(); strTerm = strTerm.toLowerCase();
if(strToSearch==strTerm)
{
return true;
}
else
{
return false;
}
}

Monday, April 6, 2009

 

Hot Keys

alt-1 - Load help

This week's code sample is JAVASCRIPT based. It traps a keyup event in a web page that contains this code. The function then goes a step further and looks for the Alt key. Once we have the Alt filtered out we can begin to look for key combinations.


Below the code sample shows traping for numeric keys. The key code is actually an ASCII representation, so therefore you will need to know some common ASCII codes. Our example shows 48, 49, 50 being used. This translates to 1, 2, 3. So in short we are making a routine that will trap the following:


  • Alt-1
  • Alt-2
  • Alt-3

Important Note: Works with IE and FireFox

Try the Alt keys.

    function handler(e)
{
//In NN4, e now holds the keyboard information
// FOR MSIE4, we can use the event object property
if ( document.all )
{
e = window.event;
}

if ( e.altKey )
{
switch ( e.keyCode )
{
// alt-1
case 49: put_your_function_here(); break;

// alt-2
case 50: break;

//alt-3 case
51: break;
}
}
}
document.onkeyup = handler;



Andrew Pallant in Nova ScotiaAndrew Pallant KayakingAndrew Pallant