I am aware of regex and several other string methods, but have not seen a built in way of checking against multiple patterns allowing for asterisks.
Curious what others have come up with.
internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties
Try asteriks preceded by "`" character, kinda "`*mybad"
if string.StartWith("`*mybad") etc
I see, escape the *, good tip.
I will try that also with the contains method, thanks
internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties
Yes, 'Contains' method will be handy in this case,
Cheers 🙂
Exactly the same as (wcmatch ...) in AutoLisp and acutWcMatch/acutWcMatchEx in ObjectARX doing:
Autodesk.AutoCAD.Internal.Utils.WcMatch(string str, string pattern); Autodesk.AutoCAD.Internal.Utils.WcMatchEx(string str, string pattern, bool ignoreCase);
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
great suggestion, I saw your same post on theswamp from a while back.
I am actually doing a non-acad project, so have to use regular .net, but still cool to have access to acad's routines.
internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties
Yes, but that's not the 'easiest' way
namespace System { public static class WcMatchExtensionMethods { public static bool Matches( this string str, string pattern, bool ignoreCase ) { return Autodesk.AutoCAD.Internal.Utils.WcMatchEx( str, pattern, ignoreCase ); } public static bool Matches( this string str, string pattern ) { return Autodesk.AutoCAD.Internal.Utils.WcMatchEx( str, pattern, true ); } } }
Honestly I have never really used Autolisp or Regex either.
This is only from 5 minutes a messing around since I thought it might be good to see what Regex was about. I only knew it had something to do with matching character in strings, but taking a quick look at WCMATCH and this article Converting Wildcards to Regexes this might be a start, but there are guys with AutoLisp and Regex experience around here and other forums that would much know a much better approach.
A little console program playing around
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace ConsoleApplication8 { class Program { static void Main(string[] args) { string poo = "I have no idea and I have spent 5 minutes on this and have no idea if it will work"; Console.WriteLine(poo.WCMATCH("*z"));/////////////////////->False Console.WriteLine(poo.WCMATCH("*al"));////////////////////->False Console.WriteLine(poo.WCMATCH("min???s"));////////////////->True Console.WriteLine(poo.WCMATCH("*z", "*al", "min???s"));///->True Console.WriteLine(poo.WCMATCH("*z", "*al", "*ha"));///->True Console.ReadLine(); } } public static class StringExtensions { public static bool WCMATCH(this string text, params string[] patterns) { foreach (string pat in patterns) { string reg = s_wildcardToRegex(pat); if (Regex.Match(text, reg).Success) { return true; } } return false; } ///////////source http://www.codeproject.com/Articles/11556/Converting-Wildcards-to-Regexes private static string s_wildcardToRegex(string pattern) { return Regex.Escape(pattern).Replace("\\*", ".*").Replace("\\?", "."); } } }
*********Edit**********
DiningPhilosopher slipped in while I was posting and prime of example of what I meant when I I said other guys would know much better than I would. Actually I never said that but typed it.
wow, thanks for all the responses.
internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties
@DiningPhilosopher wrote:
Yes, but that's not the 'easiest' way
Oh, Tony! Of course your version is beautiful and laconic. For this you have new kudos from me!
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Can't find what you're looking for? Ask the community or share your knowledge.