473,902 Members | 3,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TextBox Find and Replace !

Hi,

What do you suggest to do if I want to do a search in TextBox ? I know that
using RichTextBox, we could have Find method to search for a specific word
or information but I was wonder if somebody knows some methods for Find and
Replace in TextBox.

Thanks
Nov 15 '05
16 38222

Hi, there are some question I have for you since I"m new to C# and still not
familiar with some issues. However, please let me know why you used:
textBox.Selecti onStart = charIndex +Environment.Ne wLine.Length;

What Environement.Ne wLine is ?

also why you put : charIndex += textBox.Lines[i].Length; ?

my textbox has 10 lines but this makes it 14 and doesn't return a proper
line number after exiting the end of loop the value is 43.

any suggestions ?
thanks in advance
"C# Learner" <cs****@learner .here> wrote in message
news:9l******** *************** *********@4ax.c om...
C# Learner <cs****@learner .here> wrote:

i < textBox1.Lines. Length && i < lineIndex - 1;


that should be:
textBox.Lines.L ength

Nov 15 '05 #11
"Ramsin Savra" <rs****@otxrese arch.com> wrote:

Hi, there are some question I have for you since I"m new to C# and still not
familiar with some issues. However, please let me know why you used:
textBox.Selecti onStart = charIndex +Environment.Ne wLine.Length;

What Environement.Ne wLine is ?
Here:
http://msdn.microsoft.com/library/de...wlinetopic.asp

It's a string - "\r\n" - which is what Windows uses to specify a "new line".
also why you put : charIndex += textBox.Lines[i].Length; ?
Here, charIndex is being incremented by the length of the current line.
my textbox has 10 lines but this makes it 14 and doesn't return a proper
line number after exiting the end of loop the value is 43.
Sorry! I made an error -- I must've been half asleep when I wrote that.

Here's how it should look:

private void SetCursorToStar tOfLine(int lineIndex)
{
int charIndex = 0;

for (int i = 0; i < textBox.Lines.L ength && i < lineIndex - 1; ++i) {
charIndex += textBox.Lines[i].Length + Environment.New Line.Length;
}

textBox.Selecti onStart = charIndex;
}
any suggestions ?
thanks in advance


Nov 15 '05 #12
Thanks for help but doesn't work it generates number much bigger than
textbox.lines. I have defined 10 lines for it but the code calculates number
of characters in every line so it's not the logic I'm looking for.

regards
"Ramsin Savra" <rs****@otxrese arch.com> wrote in message
news:e8******** ******@TK2MSFTN GP11.phx.gbl...

Hi, there are some question I have for you since I"m new to C# and still not familiar with some issues. However, please let me know why you used:
textBox.Selecti onStart = charIndex +Environment.Ne wLine.Length;

What Environement.Ne wLine is ?

also why you put : charIndex += textBox.Lines[i].Length; ?

my textbox has 10 lines but this makes it 14 and doesn't return a proper
line number after exiting the end of loop the value is 43.

any suggestions ?
thanks in advance
"C# Learner" <cs****@learner .here> wrote in message
news:9l******** *************** *********@4ax.c om...
C# Learner <cs****@learner .here> wrote:

i < textBox1.Lines. Length && i < lineIndex - 1;


that should be:
textBox.Lines.L ength


Nov 15 '05 #13
"Ramsin Savra" <rs****@otxrese arch.com> wrote:
Thanks for help but doesn't work it generates number much bigger than
textbox.line s. I have defined 10 lines for it but the code calculates number
of characters in every line so it's not the logic I'm looking for.

regards


That's the whole point. It gets the *character index* of the start of
a line.

This character index is then used in "textBox.Select ionStart =
charIndex".

You can't select a line with a *line index*, as far as I know.
Nov 15 '05 #14

Thanks for keeping in touch. The thing is when we call :
charIndex += textBox.Lines[i].Length + Environment.New Line.Length;

It does a sum operatioin on textBox.lines + 2.
let's say my textBox has 10 lines and every line has some characters or
nothing ... now each iteration the value
of charIndex is being increased. Here I have text box with 10 lines; after
running the loop charIndex isn't even equal to 10 (max line number in
textbox)
only after first iteration the value of charIndex is 15 which is greater
than 10.
then how can I send the cursor to 39 (value of charIdnex after exiting the
loop)?
Or there is something that I can't get but since I've used the code you
pointed.
Again I apprecaite your concern.


"C# Learner" <cs****@learner .here> wrote in message
news:a4******** *************** *********@4ax.c om...
"Ramsin Savra" <rs****@otxrese arch.com> wrote:
Thanks for help but doesn't work it generates number much bigger than
textbox.line s. I have defined 10 lines for it but the code calculates numberof characters in every line so it's not the logic I'm looking for.

regards


That's the whole point. It gets the *character index* of the start of
a line.

This character index is then used in "textBox.Select ionStart =
charIndex".

You can't select a line with a *line index*, as far as I know.



Nov 15 '05 #15
"Ramsin Savra" <rs****@otxrese arch.com> wrote:

Thanks for keeping in touch. The thing is when we call :
charIndex += textBox.Lines[i].Length + Environment.New Line.Length;

It does a sum operatioin on textBox.lines + 2.
let's say my textBox has 10 lines and every line has some characters or
nothing ... now each iteration the value
of charIndex is being increased. Here I have text box with 10 lines; after
running the loop charIndex isn't even equal to 10 (max line number in
textbox)
only after first iteration the value of charIndex is 15 which is greater
than 10.
then how can I send the cursor to 39 (value of charIdnex after exiting the
loop)?
Or there is something that I can't get but since I've used the code you
pointed.
Again I apprecaite your concern.


Imagine you have a text box that looks like this:

Line 1.
Line 2.
Line 3.

Now, the text box is really holding this: "Line 1.\r\nLine 2.\r\n.Line
3\r\n."

To get to the start of line three, we must set the cursor position to:
Length(Line 1) + Length("\r\n") + Length(Line2) + Length("\r\n").

This is what is achieved in the loop.

I'm not quite sure what part you don't understand...
Nov 15 '05 #16
Yes, you're right. The thing is I hadn't used txtBody.Focus() ; method before
textBox.Selecti onStart = digit
so wasn't working. Not works just fine.
Thanks for your help and your patience

regards
"C# Learner" <cs****@learner .here> wrote in message
news:gj******** *************** *********@4ax.c om...
"Ramsin Savra" <rs****@otxrese arch.com> wrote:

Thanks for keeping in touch. The thing is when we call :
charIndex += textBox.Lines[i].Length + Environment.New Line.Length;

It does a sum operatioin on textBox.lines + 2.
let's say my textBox has 10 lines and every line has some characters or
nothing ... now each iteration the value
of charIndex is being increased. Here I have text box with 10 lines; afterrunning the loop charIndex isn't even equal to 10 (max line number in
textbox)
only after first iteration the value of charIndex is 15 which is greater
than 10.
then how can I send the cursor to 39 (value of charIdnex after exiting theloop)?
Or there is something that I can't get but since I've used the code you
pointed.
Again I apprecaite your concern.


Imagine you have a text box that looks like this:

Line 1.
Line 2.
Line 3.

Now, the text box is really holding this: "Line 1.\r\nLine 2.\r\n.Line
3\r\n."

To get to the start of line three, we must set the cursor position to:
Length(Line 1) + Length("\r\n") + Length(Line2) + Length("\r\n").

This is what is achieved in the loop.

I'm not quite sure what part you don't understand...

Nov 15 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1452
by: ddddd | last post by:
How do I place a Command Button on one of my forms that when pressed will open up a find/replace window that I can specify two criterias for search and then have the items I searched for show up on the form? Wow, any help is greatly appreciated!!
4
2075
by: JackRazz | last post by:
I'm trying to use Visual Studio's Find/Replace to match VB declarations. This RegEx works fine in Regulator: ^\s*(Public|Friend|Protected|Private)*\s*(Shared|Overrides)*\s*(Sub|Function|Property )+ But when I try it in Visual Studio's find (with regular expressions turned on) it doesn't work. Are there any known problems with VS find or is there something wrong with the above expression? I'm new to them, so the second question...
2
1650
by: :\\\\derian | last post by:
anyone know where i could find the equivalent of the find / replace windows control for my project? :\\derian
2
10020
by: scorpion53061 | last post by:
This excel find/replace code works great under Excel 2003 but bombs with an error (pasted below the code) in Excel 2000. Can anyone suggest an alternative to make both happy? I am using vb.net windows application. I also tried creating an object and assigning the find/replace event to it but I also received errors. I am a little under the gun on this one.... WSheet.Application.Selection.Replace(What:="NONE", Replacement:="",...
0
1125
by: D Brown | last post by:
Does anyone know why my .NET development would hang / freeze when performing a Global Find / Replace on all files? I have a large ASP.NET VB Application. I have left the machine for 24 hours but to no avail. I have to reboot the machine, delete the WebCache'd version of the application else I get the error message "Unable to get the project from the web server". I can perform a Find / Replace on each file in turn with no issues which...
0
1237
by: vipal.keshwala | last post by:
I just migrated the access data base onto a new server but when I open the application up and click on find/replace in the find what field I try to right click a paste some information, but the only option I have it says "what is this" Please Help!!!!!!!!
0
1577
by: Scott | last post by:
Ok I am using the code below to set the default find option but it does not seem to stick. I query the option with getoptions and it is set to 1 but when the find dialog opens it still is set to whole field. I know the code is firing, any ideas why it is not showing the option I set via code. Application.SetOption "Default Find/Replace Behavior", 1 Access 2003, Windows XP Pro
8
2735
by: John Pye | last post by:
Hi all I have a file with a bunch of perl regular expressions like so: /(^|)\*(.*?)\*(|$)/$1'''$2'''$3/ # bold /(^|)\_\_(.*?)\_\_(|$)/$1''<b>$2<\/ b>''$3/ # italic bold /(^|)\_(.*?)\_(|$)/$1''$2''$3/ # italic
4
4986
by: Elliot Fraval | last post by:
Hi All, Environment is VBA code in Access 2007. I am having some problems performing a find and replace on text that originates from a memo field in a table. The code is supposed to take internal document tracking numbers and replace them with simpler document number in reports for external clients, so the search string, or 'delimiter' is ~10 characters depending on document name. I have used several methods involving the VBA functions:...
0
9997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9845
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11279
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10981
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9675
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7205
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5893
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4307
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.