Click here to Skip to main content
15,887,405 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionCount char in string? Pin
Member 1395409621-Aug-18 22:43
Member 1395409621-Aug-18 22:43 
AnswerRe: Count char in string? Pin
Jochen Arndt21-Aug-18 23:32
professionalJochen Arndt21-Aug-18 23:32 
GeneralRe: Count char in string? Pin
Chris Quinn22-Aug-18 4:23
Chris Quinn22-Aug-18 4:23 
GeneralRe: Count char in string? Pin
Jochen Arndt22-Aug-18 5:08
professionalJochen Arndt22-Aug-18 5:08 
GeneralRe: Count char in string? Pin
Richard Deeming22-Aug-18 8:58
mveRichard Deeming22-Aug-18 8:58 
GeneralRe: Count char in string? Pin
Chris Quinn22-Aug-18 20:55
Chris Quinn22-Aug-18 20:55 
GeneralRe: Count char in string? Pin
Jochen Arndt22-Aug-18 21:16
professionalJochen Arndt22-Aug-18 21:16 
GeneralRe: Count char in string? Pin
Chris Quinn22-Aug-18 21:40
Chris Quinn22-Aug-18 21:40 
It will be highly dependent on the length of the strings. I had reason to write such a function a while back in tSQL for a database system and using the native Replace functionality was much more efficient than looping in all but the shortest of strings, but YMMV.
VB
Module Module1

    Sub Main()
        Dim iCount As Integer
        Dim strToSearch As String = "Every instance. Replace() will inteiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiirnally loop throughiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii the entire source string. It replaces all occurrences of the substring you want to replace. Tip: This behavior is useful when dealing with common string replacements in programs.  But: If you do not understand this behavior you may end up writing inefficient code that has unneeded loops. "
        Dim strSearchFor As String = "i"
        Console.WriteLine(strToSearch)
        iCount = strToSearch.Length() - strToSearch.Replace(strSearchFor, "").Length
        Console.WriteLine("There are " + iCount.ToString() + " letter " + strSearchFor + "'s in the string")

    End Sub

End Module
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================

GeneralRe: Count char in string? Pin
Richard Deeming23-Aug-18 9:03
mveRichard Deeming23-Aug-18 9:03 
AnswerRe: Count char in string? Pin
Chris Quinn23-Aug-18 3:19
Chris Quinn23-Aug-18 3:19 
QuestionAlternative to FileCopy in Visual Basic 6 for 2GB files up Pin
paolo71xx21-Aug-18 6:58
paolo71xx21-Aug-18 6:58 
AnswerRe: Alternative to FileCopy in Visual Basic 6 for 2GB files up Pin
Dave Kreskowiak21-Aug-18 8:09
mveDave Kreskowiak21-Aug-18 8:09 
GeneralRe: Alternative to FileCopy in Visual Basic 6 for 2GB files up Pin
paolo71xx21-Aug-18 8:28
paolo71xx21-Aug-18 8:28 
GeneralRe: Alternative to FileCopy in Visual Basic 6 for 2GB files up Pin
Dave Kreskowiak21-Aug-18 9:25
mveDave Kreskowiak21-Aug-18 9:25 
GeneralRe: Alternative to FileCopy in Visual Basic 6 for 2GB files up Pin
paolo71xx21-Aug-18 10:04
paolo71xx21-Aug-18 10:04 
GeneralRe: Alternative to FileCopy in Visual Basic 6 for 2GB files up Pin
Dave Kreskowiak21-Aug-18 10:11
mveDave Kreskowiak21-Aug-18 10:11 
GeneralRe: Alternative to FileCopy in Visual Basic 6 for 2GB files up Pin
paolo71xx23-Aug-18 2:25
paolo71xx23-Aug-18 2:25 
QuestionThe Problem in Update Command with Table Adapter VB.net Pin
Member 128130745-Aug-18 18:29
Member 128130745-Aug-18 18:29 
AnswerRe: The Problem in Update Command with Table Adapter VB.net Pin
CHill606-Aug-18 1:54
mveCHill606-Aug-18 1:54 
AnswerRe: The Problem in Update Command with Table Adapter VB.net Pin
Richard MacCutchan6-Aug-18 3:10
mveRichard MacCutchan6-Aug-18 3:10 
GeneralRe: The Problem in Update Command with Table Adapter VB.net Pin
Member 128130746-Aug-18 15:55
Member 128130746-Aug-18 15:55 
GeneralRe: The Problem in Update Command with Table Adapter VB.net Pin
Richard MacCutchan6-Aug-18 20:54
mveRichard MacCutchan6-Aug-18 20:54 
GeneralRe: The Problem in Update Command with Table Adapter VB.net Pin
Dave Kreskowiak7-Aug-18 6:14
mveDave Kreskowiak7-Aug-18 6:14 
GeneralRe: The Problem in Update Command with Table Adapter VB.net Pin
Member 128130747-Aug-18 15:37
Member 128130747-Aug-18 15:37 
GeneralRe: The Problem in Update Command with Table Adapter VB.net Pin
Member 128130747-Aug-18 22:57
Member 128130747-Aug-18 22:57 

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.