Click here to Skip to main content
16,015,218 members
Home / Discussions / C#
   

C#

 
GeneralRe: Group Sequance patterns with Linq Pin
Member 121069269-Sep-16 2:19
Member 121069269-Sep-16 2:19 
GeneralRe: Group Sequance patterns with Linq Pin
#realJSOP9-Sep-16 2:25
professional#realJSOP9-Sep-16 2:25 
GeneralRe: Group Sequance patterns with Linq Pin
Member 121069269-Sep-16 2:28
Member 121069269-Sep-16 2:28 
SuggestionRe: Group Sequance patterns with Linq Pin
Richard Deeming9-Sep-16 4:15
mveRichard Deeming9-Sep-16 4:15 
GeneralRe: Group Sequance patterns with Linq Pin
#realJSOP9-Sep-16 4:18
professional#realJSOP9-Sep-16 4:18 
GeneralRe: Group Sequance patterns with Linq Pin
Richard Deeming9-Sep-16 4:19
mveRichard Deeming9-Sep-16 4:19 
GeneralRe: Group Sequance patterns with Linq Pin
#realJSOP9-Sep-16 4:25
professional#realJSOP9-Sep-16 4:25 
AnswerRe: Group Sequance patterns with Linq Pin
Member 121069269-Sep-16 2:26
Member 121069269-Sep-16 2:26 
Here is my simple test utility that i used to test my code. It's not elegant but does the job. Smile | :)

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace TestSubjectMatterReco
{
    class Program
    {
        static void Main(string[] args)
        {
            bool run = true;
            while (run)
            {
                Console.WriteLine("Add string to use");
                string subject = Console.ReadLine();
                Console.WriteLine("Add Pattern Line to use");
                string Pattern = Console.ReadLine();
                var sout = Parse(subject, Pattern);

                if (sout.Count() == 0)
                    Console.WriteLine("Unable to detect pattern");
                else
                {
                    int i = 1;
                    sout.ForEach(p => {  Console.WriteLine($"found pattern {p} this is pattern nr {i} of {sout.Count()}"); i++; });
                }                                                                            
                Console.WriteLine("----------------------------------");
                Console.WriteLine();
                Console.WriteLine("Press enter to try again , use q to qwuit");
                var answer = Console.ReadLine();
                if (answer=="q")
                    run = false;
            }            
            
        }        
        static List<string> Parse(string subject, string pattern)
        {
            var subjectList = subject.Split(' ').ToList().Where(p => p.Length == pattern.Length).ToList();
            string result = "";
            //so we have a substring with a lenght that mattches our pattern lenght. 
            if (subjectList.Count() > 0)
            {
                #region break down pattern
                List<string> _patterns = new List<string>();                
                string patt = string.Empty;
                int currindex = 0;          
                foreach (char c in pattern.ToCharArray())
                {                 
                    currindex++;   
                    if (patt == string.Empty)                    
                        patt = c.ToString();                                         
                    else
                    {
                        if (patt.StartsWith(c.ToString()))                        
                            patt += c.ToString();                                                    
                        else
                        {
                            _patterns.Add(patt);
                            patt = c.ToString();                            
                        }
                    }
                    if(currindex == pattern.Length)
                        _patterns.Add(patt);
                }
                int indexinSubjct = 0;
                #endregion
                #region try to find text that fits the pattern
                foreach (string pair in _patterns)
                {
                    //start at the beging.                                         
                    for (int j = subjectList.Count; j > 0; j--)
                    {
                        if (pair.StartsWith("D"))
                        {
                            if (!ParseDigit(subjectList[j-1].Substring(indexinSubjct, pair.Length)))
                                subjectList.Remove(subjectList[j-1]);
                        }
                        else if (pair.StartsWith("A"))
                        {
                            if (!ParseLetter(subjectList[j-1].Substring(indexinSubjct, pair.Length)))
                                subjectList.Remove(subjectList[j-1]);
                        }
                        else
                        {
                            string part = subjectList[j - 1].Substring(indexinSubjct, pair.Length);
                            if(part != pair)
                                subjectList.Remove(subjectList[j - 1]);
                        }
                        //seperator
                    }
                    indexinSubjct += pair.Length;
                }
                return subjectList;                
            }
            return new List<string>();
            #endregion  
        }        
        static bool ParseLetter(string sequence)
        {
           return sequence.All(p => char.IsLetter(p));
        }
        static bool ParseDigit(string sequence)
        {
            return sequence.All(p => char.IsDigit(p));
        }
        
    }
}

AnswerRe: Group Sequance patterns with Linq Pin
Gerry Schmitz9-Sep-16 13:30
mveGerry Schmitz9-Sep-16 13:30 
AnswerRe: Group Sequance patterns with Linq Pin
BillWoodruff10-Sep-16 2:34
professionalBillWoodruff10-Sep-16 2:34 
GeneralRe: Group Sequance patterns with Linq Pin
#realJSOP11-Sep-16 3:18
professional#realJSOP11-Sep-16 3:18 
GeneralRe: Group Sequance patterns with Linq Pin
BillWoodruff11-Sep-16 19:21
professionalBillWoodruff11-Sep-16 19:21 
Questionunable to bind json data in label Pin
Member 127294328-Sep-16 22:36
Member 127294328-Sep-16 22:36 
QuestionRe: unable to bind json data in label Pin
Richard MacCutchan8-Sep-16 22:40
mveRichard MacCutchan8-Sep-16 22:40 
AnswerRe: unable to bind json data in label Pin
Member 127294328-Sep-16 22:46
Member 127294328-Sep-16 22:46 
GeneralRe: unable to bind json data in label Pin
Richard MacCutchan8-Sep-16 22:53
mveRichard MacCutchan8-Sep-16 22:53 
AnswerRe: unable to bind json data in label Pin
Simon_Whale8-Sep-16 22:52
Simon_Whale8-Sep-16 22:52 
QuestionC# Website - PDF viewer to extract info Pin
NickyRamshaw8-Sep-16 3:12
NickyRamshaw8-Sep-16 3:12 
AnswerRe: C# Website - PDF viewer to extract info Pin
Nathan Minier8-Sep-16 5:49
professionalNathan Minier8-Sep-16 5:49 
QuestionRifidi connection Pin
Member 116390998-Sep-16 0:20
Member 116390998-Sep-16 0:20 
AnswerRe: Rifidi connection Pin
phil.o8-Sep-16 1:24
professionalphil.o8-Sep-16 1:24 
Generalhow to work on toggle button when two text fields in which we need one field require and save data and another second filed control toggle button. Pin
nadir malik7-Sep-16 21:45
nadir malik7-Sep-16 21:45 
GeneralRe: how to work on toggle button when two text fields in which we need one field require and save data and another second filed control toggle button. Pin
OriginalGriff7-Sep-16 21:58
mveOriginalGriff7-Sep-16 21:58 
Questionnoob need some help Pin
jimboo12327-Sep-16 7:31
jimboo12327-Sep-16 7:31 
AnswerRe: noob need some help Pin
OriginalGriff7-Sep-16 8:06
mveOriginalGriff7-Sep-16 8:06 

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.