Click here to Skip to main content
15,904,346 members
Home / Discussions / C#
   

C#

 
GeneralWM_NCLBUTTONUP Pin
Guinness4Strength29-Jul-04 12:34
Guinness4Strength29-Jul-04 12:34 
GeneralRe: WM_NCLBUTTONUP Pin
Nick Parker29-Jul-04 17:38
protectorNick Parker29-Jul-04 17:38 
GeneralRe: WM_NCLBUTTONUP Pin
Guinness4Strength30-Jul-04 3:29
Guinness4Strength30-Jul-04 3:29 
GeneralRe: WM_NCLBUTTONUP Pin
Heath Stewart30-Jul-04 4:37
protectorHeath Stewart30-Jul-04 4:37 
GeneralArrayList Help Needed for Newbie... Pin
gman4429-Jul-04 11:32
gman4429-Jul-04 11:32 
GeneralRe: ArrayList Help Needed for Newbie... Pin
Christian Graus29-Jul-04 11:52
protectorChristian Graus29-Jul-04 11:52 
GeneralRe: ArrayList Help Needed for Newbie... Pin
leppie29-Jul-04 21:41
leppie29-Jul-04 21:41 
GeneralWildcard filename pattern matching for c# Pin
RobC.29-Jul-04 11:29
RobC.29-Jul-04 11:29 
For those of you wanting to use file system type pattern matching on strings, here is some code for you. For example, you can use *, ?, and # wildcards in your pattern and test a string against it to see if it matches. This is similar to the VB LIKE function.
Ref: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/html/vxgrfwildcards.asp

*********Code follows************
///
/// Matches the pattern and string.
///

/// <param name="pText" />The Text string to be matched.
/// <param name="pPattern" />The pattern containing *, ?, and # wildcards.
/// <param name="pIgnoreCase" />True=Ignore Case.
/// <returns>True if the text and pattern match.
public static bool Like(string pText, string pPattern, bool pIgnoreCase)
{
bool retVal = false;
if(pText == null || pPattern == null)
{
return retVal;
}
if(pText.Length == 0 || pPattern.Length == 0)
{
return retVal;
}

if(pPattern == "*" || pPattern == "*.*")
{
retVal = true;
}
else
{ //Replace the pattern matching characters with temp values
//So all other characters can be escaped
pPattern = pPattern.Replace(@"*","\xfc");
pPattern = pPattern.Replace(@"?","\xfd");
pPattern = pPattern.Replace(@"#","\xfe");
//Escape all other characters
pPattern = Regex.Escape(pPattern);
//Replace the temp values with the required regular expressions
pPattern = pPattern.Replace("\xfc",@".*[^.]");
pPattern = pPattern.Replace("\xfd",@".");
pPattern = pPattern.Replace("\xfe",@"[0-9]");

if(pIgnoreCase == false)
{
retVal = Regex.IsMatch(pText, pPattern, RegexOptions.Compiled);
}
else
{
retVal = Regex.IsMatch(pText, pPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);
}
}
return retVal;
}

private void TestTheLikeFunction ()
{
bool val;
// should return true
val = (Like(@"workbook.xls",@"*.xls",true));
val = (Like(@"workbook.xls",@"workbook*",true));
val = (Like(@"workbook.xls",@"workbook.*",true));
val = (Like(@"workbook.xls",@"work*.xls",true));
val = (Like(@"workbook.xls",@"work????.*",true));
val = (Like(@"workbook.xls",@"work*.*",true));
val = (Like(@"workbook.xls",@"*orkbook.xls",true));
val = (Like(@"workbook.xls",@"?orkbook.xls",true));
val = (Like(@"workbook.xls",@"?orkb??k.xls",true));
val = (Like(@"abcxls",@"*xls",true));
val = (Like(@"abcxls",@"???xls",true));
val = (Like(@"ab1xls",@"??#xls",true));
val = (Like(@"a12xls",@"?##xls",true));

// should return false
val = (Like(@"abcxls",@"#*",true));
val = (Like(@"abcxls",@"?#?xls",true));
val = (Like(@"abcxls",@"*.xls",true));
val = (Like(@"abcxls",@"*xls?",true));
val = (Like(@"abcxls",@"????xls",true));
val = (Like(@"workbook.xls",@"workbooke.*",true));
val = (Like(@"workbook.xls",@"work*xls",true));
val = (Like(@"workbook.xls",@"work?????.*",true));
val = (Like(@"workbook.xls",@"work???.*",true));
}


RobC
GeneralRe: Wildcard filename pattern matching for c# Pin
Nick Parker29-Jul-04 12:37
protectorNick Parker29-Jul-04 12:37 
GeneralSetting default button in a user control Pin
Member 117376029-Jul-04 11:18
Member 117376029-Jul-04 11:18 
GeneralRe: Setting default button in a user control Pin
Member 117376030-Jul-04 2:20
Member 117376030-Jul-04 2:20 
GeneralRe: Setting default button in a user control Pin
Heath Stewart30-Jul-04 4:33
protectorHeath Stewart30-Jul-04 4:33 
GeneralRe: Setting default button in a user control Pin
Member 117376030-Jul-04 4:50
Member 117376030-Jul-04 4:50 
Generalmp3 player Pin
Member 80940929-Jul-04 11:04
Member 80940929-Jul-04 11:04 
GeneralRe: mp3 player Pin
Nick Parker29-Jul-04 11:36
protectorNick Parker29-Jul-04 11:36 
GeneralRe: mp3 player Pin
crushinghellhammer29-Jul-04 12:17
crushinghellhammer29-Jul-04 12:17 
QuestionDrawing twice causes exception? Pin
Pain_Elemental29-Jul-04 9:34
Pain_Elemental29-Jul-04 9:34 
AnswerRe: Drawing twice causes exception? Pin
Heath Stewart29-Jul-04 9:42
protectorHeath Stewart29-Jul-04 9:42 
GeneralRe: Drawing twice causes exception? Pin
Pain_Elemental29-Jul-04 20:26
Pain_Elemental29-Jul-04 20:26 
GeneralRe: Drawing twice causes exception? Pin
Heath Stewart30-Jul-04 3:13
protectorHeath Stewart30-Jul-04 3:13 
GeneralRe: Drawing twice causes exception? Pin
Pain_Elemental30-Jul-04 3:34
Pain_Elemental30-Jul-04 3:34 
GeneralRe: Drawing twice causes exception? Pin
Pain_Elemental30-Jul-04 10:37
Pain_Elemental30-Jul-04 10:37 
GeneralDifferent behavior on different machines Pin
DougW4829-Jul-04 9:22
DougW4829-Jul-04 9:22 
GeneralRe: Different behavior on different machines Pin
Heath Stewart29-Jul-04 9:36
protectorHeath Stewart29-Jul-04 9:36 
GeneralRe: Different behavior on different machines Pin
DougW4829-Jul-04 9:59
DougW4829-Jul-04 9:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.