Solved

urgent String logic

Posted on 2004-08-26
11
150 Views
Last Modified: 2010-05-02
Hi
In Sapi 5.1 I m dealing with two events

Private Sub RecoContext_Hypothesis(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal Result As SpeechLib.ISpeechRecoResult)

and return a string
list1.additem  = Result.PhraseInfo.GetText

it runs many time and as in end I want to know how many items are in list group by same items
for example

this is
this is simple
this is
this is soft
this is simple
this is simple

and results must be like this

this is 2 times
this is simple 3 times
this is soft 1 time
and over all same word like
this 6 times
is 6 times
this is 6 times

plz take some time to solve this.
I tried many ways but can not
thanks

 
0
Comment
Question by:SCS_SU
  • 3
  • 2
  • 2
  • +1
11 Comments
 
LVL 9

Expert Comment

by:dancebert
Comment Utility
create a collection.  For each phrase (e.g. "this is"), check to see if there is a member already in the collection with the phrase as the key.  If it's already there, increment the member by one.  If it's not there, add a new member and set it's value to one.

To determine the count for the individual words, do the same thing as above for each word instead of each phrase.
0
 

Expert Comment

by:kirshan
Comment Utility
can  u plz write codes
I got u but today due to lot of work I can not code these.
I tried but can not and I need solution as soon as posible to move other sides.

plz
thanks
0
 
LVL 11

Accepted Solution

by:
coopzz earned 30 total points
Comment Utility
Option Explicit

'you'll need a reference to Microsoft Scripting Runtime
Private m_oColl As Scripting.Dictionary

Private Sub Command1_Click()
    Randomize
    Dim sNew As String
    Select Case (Int((5 - 1 + 1) * Rnd + 1))
        Case 1: sNew = "this is"
        Case 2: sNew = "this was"
        Case 3: sNew = "this can be"
        Case 4: sNew = "this saw"
        Case 5: sNew = "this believed"
    End Select
   
    Dim n As Integer
    If (m_oColl.Exists(sNew)) Then
        m_oColl.Item(sNew) = m_oColl.Item(sNew) + 1
    Else
        m_oColl.Add sNew, 1
    End If
   
    displayResult
End Sub

Private Sub displayResult()
    Dim i As Variant
    List1.Clear
    For Each i In m_oColl
        List1.AddItem i & ": " & m_oColl.Item(i) & " times"
    Next i
End Sub

Private Sub Form_Load()
    Set m_oColl = New Scripting.Dictionary
End Sub

Hope it helps..
0
 

Expert Comment

by:kirshan
Comment Utility
thanks I will chk it and let u know results.
thanks


0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 7

Expert Comment

by:OHDev2004
Comment Utility
why not using the Precios "Instr" function :P

here's How:
'=========================================
Private Function CountItems (StringtoFind as String , ListtoSearch as Listbox) as Long
Dim Xloop as Long
For Xloop = 0 to ListtoSearch.Listcount - 1
If Instr (1, ListtoSearch.List(Xloop), StringtoFind) <> 0 Then CountItems = CountItems + 1
Next Xloop
End Function
'=========================================

and now to test the Function :
let's say you want to count the "this is" from a Combobox called "List1"
msgbox CountItems("this is", List1)

Cheers
OHDev
0
 
LVL 7

Expert Comment

by:OHDev2004
Comment Utility
"let's say you want to count the "this is" from a COMBOBOX called "List1" "
sorry i meant Listbox not Combobox :P ...
OHDev
0
 
LVL 11

Expert Comment

by:coopzz
Comment Utility
?¿ so did this help ¿? or Not.
0
 
LVL 11

Expert Comment

by:coopzz
Comment Utility
I think my comment deserved some of the points.. it did give a solution after some code was asked for.

but if you read the whole it's a bit strange how it started with scs_su then was getting author type comments from krishan  hmmm...
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now