Click here to Skip to main content
15,921,716 members
Home / Discussions / Visual Basic
   

Visual Basic

 
Questioncount character frequency Pin
Cool Smith11-Feb-11 3:24
Cool Smith11-Feb-11 3:24 
AnswerRe: count character frequency Pin
Tieske811-Feb-11 4:18
professionalTieske811-Feb-11 4:18 
GeneralRe: count character frequency Pin
Cool Smith11-Feb-11 4:31
Cool Smith11-Feb-11 4:31 
GeneralRe: count character frequency Pin
Tieske811-Feb-11 6:02
professionalTieske811-Feb-11 6:02 
GeneralRe: count character frequency Pin
Dave Kreskowiak11-Feb-11 6:17
mveDave Kreskowiak11-Feb-11 6:17 
AnswerRe: count character frequency Pin
Eddy Vluggen11-Feb-11 10:20
professionalEddy Vluggen11-Feb-11 10:20 
GeneralRe: count character frequency Pin
Cool Smith11-Feb-11 22:19
Cool Smith11-Feb-11 22:19 
GeneralRe: count character frequency Pin
Eddy Vluggen11-Feb-11 23:48
professionalEddy Vluggen11-Feb-11 23:48 
Cool Smith wrote:
i found code here that can detect the code page of a file

Can you post a link to that article? I haven't read it yet Smile | :)

Cool Smith wrote:
can you give me pseudo code for this
It'd go something like this;
C#
// A dictionary, used to count the frequencies
Dictionary<String, Int64> characterCounter = new Dictionary<String, Int64>();

// we'll read the entire file into a string;
string theFile = File.ReadAllText("C:\test.txt");

// we'll keep removing characters and process them, until the string is empty
while (theFile.Length > 0)
{
  // get the char at the end of the string
  string CurrentCharacter = theFile[theFile.Length -1];  

  // remove that thing from the string that holds the file
  string theFile = theFile.Remove(theFile.Length -1, 1); 

  // if the dictionary contains our character
  if (characterCounter.ContainsKey(CurrentCharacter))
  {
    // increase the value of the int
    characterCounter[CurrentCharacter] = characterCounter[CurrentCharacter] + 1;
  }
  else
  {
    // it wasn't in the dictionary yet, so it must be the 
    // first time that we encounter this character. Add it;
    characterCounter.Add(CurrentCharacter, 1);
  }
}

// done with counting, now show the results to the user
for each (DictionaryEntry<String, Int64> entry in characterCounter)
{
  textBox1.Text += String.Format("char {0} occurs {1} times", entry.Key, entry.Value);
}
This could be a bit slow with large files, as it forces .NET to allocate memory each time for a new string. It'd be more efficient if it were a moving frame. That'd go something more like this;
C#
string theFile = File.ReadAllText("C:\test.txt");

// this will point to the index of the character that we're processing
Int64 currentPos = 0; 
Int64 endPos = theFile.Length -1;

// while the current position in the string doesn't match the end position;
while (currentPos <> endPos)
{
    // fetch the current character from the string, at the current index
    string CurrentCharacter = theFile[currentPos];

    // increase the index
    currentPos = currentPos + 1;

    // rest of dictionary-code here;
    ...
}

I are Troll Suspicious | :suss:

GeneralRe: count character frequency Pin
Cool Smith12-Feb-11 0:42
Cool Smith12-Feb-11 0:42 
GeneralRe: count character frequency Pin
Cool Smith12-Feb-11 4:00
Cool Smith12-Feb-11 4:00 
GeneralRe: count character frequency Pin
Eddy Vluggen12-Feb-11 5:43
professionalEddy Vluggen12-Feb-11 5:43 
QuestionStoring Binary Data in SQL Database with VB.NET Pin
Central_IT10-Feb-11 3:31
Central_IT10-Feb-11 3:31 
AnswerRe: Storing Binary Data in SQL Database with VB.NET Pin
Simon_Whale10-Feb-11 3:41
Simon_Whale10-Feb-11 3:41 
QuestionThreading question; cross thread communication/invokation Pin
Tieske89-Feb-11 23:26
professionalTieske89-Feb-11 23:26 
AnswerRe: Threading question; cross thread communication/invokation Pin
Luc Pattyn10-Feb-11 3:46
sitebuilderLuc Pattyn10-Feb-11 3:46 
QuestionRe: Threading question; cross thread communication/invokation Pin
Tieske811-Feb-11 0:14
professionalTieske811-Feb-11 0:14 
AnswerRe: Threading question; cross thread communication/invokation Pin
Luc Pattyn11-Feb-11 0:38
sitebuilderLuc Pattyn11-Feb-11 0:38 
GeneralRe: Threading question; cross thread communication/invokation Pin
Tieske811-Feb-11 2:54
professionalTieske811-Feb-11 2:54 
QuestionGetting Email Address from Exchange Server Pin
Dominick Marciano9-Feb-11 16:49
professionalDominick Marciano9-Feb-11 16:49 
AnswerRe: Getting Email Address from Exchange Server Pin
Eddy Vluggen10-Feb-11 7:22
professionalEddy Vluggen10-Feb-11 7:22 
GeneralRe: Getting Email Address from Exchange Server Pin
Dominick Marciano10-Feb-11 8:19
professionalDominick Marciano10-Feb-11 8:19 
GeneralRe: Getting Email Address from Exchange Server Pin
Eddy Vluggen10-Feb-11 8:41
professionalEddy Vluggen10-Feb-11 8:41 
JokeRe: Getting Email Address from Exchange Server Pin
phil.o10-Feb-11 23:38
professionalphil.o10-Feb-11 23:38 
QuestionCapture Unicode Character From Keyboard Hook Pin
Anubhava Dimri8-Feb-11 18:58
Anubhava Dimri8-Feb-11 18:58 
QuestionIn need of help on VB Pin
Zyprost6-Feb-11 22:56
Zyprost6-Feb-11 22:56 

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.