2014-03-13 2 views
1

같은 일을하려고합니다 : Find The Common Occurrences Of Words In Two Strings하지만 VB.net에서 원합니다.두 문자열에서 단어의 흔적을 찾으십시오

Dim tester As String = "a string with a lot of words" 
    sentence = sentence & " " 
    Dim regex As New Regex("/[^\s]+/g") 
    Dim m As Match = regex.Match(tester) 

    'not working 
    Dim regex2 As Regex = New Regex("(" + regex.Match(tester).join("|") + ")\\W", "g") 

당신은 내가 VB.net이 점을 넣어 도울 수 : 여기

var tester = "a string with a lot of words"; 

function getMeRepeatedWordsDetails (sentence) { 
    sentence = sentence + " "; 
    var regex = /[^\s]+/g; 
    var regex2 = new RegExp ("(" + tester.match (regex).join ("|") + ")\\W", "g"); 
    matches = sentence.match (regex2); 
    var words = {}; 
    for (var i = 0; i < matches.length; i++) { 
    var match = matches [ i ].replace (/\W/g, ""); 
    var w = words [ match ]; 
    if (! w) 
     words [ match ] = 1; 
    else 
     words [ match ]++; 
    } 
    return words; 
} 

console.log (getMeRepeatedWordsDetails ("another string with some words")); 

는 지금까지이 무엇입니까?

답변

0

나는 내가 그것을 알아 냈다고 생각한다

'string of interest 
    Dim sentence As String = "check this string with some words" 
    sentence = sentence & " " 

    'this is our base string 
    Dim BaseStr As String = "base string with a lot of words" 

    'use this one liner to create the pattern 
    Dim pattern2 As String = "(" & BaseStr.Replace(" ", "|") & ")\W" 

    'set up the regex 
    Dim regex As New Regex(pattern2) 
    Dim mc As MatchCollection 
    mc = regex.Matches(sentence) 

    'loop to get the results 
    For ct As Integer = 0 To mc.Count - 1 
     Dim m As Match = mc.Item(ct) 
     If m.Success Then 
      'returns two groups; get the second without a space 
      Debug.Print(m.Groups(1).Captures(0).ToString() & "<<") 
     End If 
    Next 
관련 문제