• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0

Count occurrences in selected text

4 posts in this topic

Does anyone know of any applications that can count an occurance of a letter or word or whatever in highlighted text? Im trying to count the number of times a ',' is occurring in a file, but in only the text i have highlighted. Ive tried it in a few apps, Notepad++, in its Find Dialog, has the option to count, and a checkbox to select for "selected text" only, but for me, still seems to count occurances in the whole file. Context, has no count option UltraEdit, will only count on whole files, when selecting the "selection only", then greys out the count option. Also, another function ive been trying to find, is an editor that allows you to view selected data in any format. So say i have a hex editor app open, and i have a number of selected hex characters highlighted, i can view the selcted data as floats or ints or int64 etc etc Im on Windows BTW

Share this post

Link to post
Share on other sites
Here, happy birthday.

using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
public class FormFind : Form
private TableLayoutPanel tableLayoutPanel1;
private MenuStrip menuStrip1;
private ToolStripMenuItem fileToolStripMenuItem;
private ToolStripMenuItem openToolStripMenuItem;
private ToolStripMenuItem exitToolStripMenuItem;
private TextBox textBox1;
private TextBox textBox2;
private Button button1;
private OpenFileDialog openFileDialog1;
private CheckBox checkBox1;

/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
if (disposing && (components != null))

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.checkBox1 = new System.Windows.Forms.CheckBox();
// tableLayoutPanel1
this.tableLayoutPanel1.ColumnCount = 3;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 106F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 59F));
this.tableLayoutPanel1.Controls.Add(this.menuStrip1, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.textBox1, 0, 1);
this.tableLayoutPanel1.Controls.Add(this.textBox2, 0, 2);
this.tableLayoutPanel1.Controls.Add(this.button1, 2, 1);
this.tableLayoutPanel1.Controls.Add(this.checkBox1, 1, 1);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(0);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 3;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 25F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 29F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(654, 341);
this.tableLayoutPanel1.TabIndex = 0;
// menuStrip1
this.tableLayoutPanel1.SetColumnSpan(this.menuStrip1, 3);
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(654, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
// fileToolStripMenuItem
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
this.fileToolStripMenuItem.Text = "&FIle";
// openToolStripMenuItem
this.openToolStripMenuItem.Name = "openToolStripMenuItem";
this.openToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.openToolStripMenuItem.Text = "&Open";
this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
// exitToolStripMenuItem
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
this.exitToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.exitToolStripMenuItem.Text = "E&xit";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
// textBox1
this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.textBox1.Location = new System.Drawing.Point(3, 28);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(483, 20);
this.textBox1.TabIndex = 1;
// textBox2
this.textBox2.AcceptsReturn = true;
this.textBox2.AcceptsTab = true;
this.tableLayoutPanel1.SetColumnSpan(this.textBox2, 3);
this.textBox2.Dock = System.Windows.Forms.DockStyle.Fill;
this.textBox2.Location = new System.Drawing.Point(3, 57);
this.textBox2.Multiline = true;
this.textBox2.Name = "textBox2";
this.textBox2.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.textBox2.Size = new System.Drawing.Size(648, 281);
this.textBox2.TabIndex = 2;
this.textBox2.WordWrap = false;
// button1
this.button1.Dock = System.Windows.Forms.DockStyle.Fill;
this.button1.Location = new System.Drawing.Point(598, 28);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(53, 23);
this.button1.TabIndex = 3;
this.button1.Text = "Count!";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
// openFileDialog1
this.openFileDialog1.FileName = "openFileDialog1";
// checkBox1
this.checkBox1.AutoSize = true;
this.checkBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.checkBox1.Location = new System.Drawing.Point(492, 28);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(100, 23);
this.checkBox1.TabIndex = 4;
this.checkBox1.Text = "Case Sensitive";
this.checkBox1.UseVisualStyleBackColor = true;
// FormFind
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(654, 341);
this.MainMenuStrip = this.menuStrip1;
this.Name = "FormFind";
this.Text = "Find In Selected Text";


public FormFind()

/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
Application.Run(new FormFind());

private void exitToolStripMenuItem_Click(object sender, EventArgs e)

private void openToolStripMenuItem_Click(object sender, EventArgs e)
if (openFileDialog1.ShowDialog() == DialogResult.OK)
textBox2.Text = System.IO.File.ReadAllText(openFileDialog1.FileName);

private void button1_Click(object sender, EventArgs e)
string find = textBox1.Text;
string text = textBox2.Text;
if (textBox2.SelectionLength > 0)
text = textBox2.SelectedText;
if (!checkBox1.Checked)
find = find.ToLower();
text = text.ToLower();
int count = text.IndexOf(find) == 0 ? 0 : -1;
for (int i = 0; -1 < i && i < text.Length; i = text.IndexOf(find, i + 1))
MessageBox.Show(string.Format("{0} occurances", count));


Share this post

Link to post
Share on other sites
On Textpad, if I wanted to count occurrences, I suppose I could do a "find and replace" within selected text, while using the same string in both the find and replace boxes. That would give me a note of the number of occurrences, and shouldn't affect anything.

If needed, I could simply undo the replace as well ... that might be needed, if the search was some type of regex, where the "find" string and the "replace" string might not be able to have the same value.

This trick might work on other editors, too.

Share this post

Link to post
Share on other sites
ha ha capn_midnight,
That works great :)

That also works great too HostileExpanse.


Share this post

Link to post
Share on other sites
In Vim, I select the text, do :%s/,//g (well, actually the command is :'<,'>%s/,//g but Vim fills in the '<,'> part), note the report of how many substitutions were made, and then undo (or quit without saving, as appropriate).

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0