473,840 Members | 1,479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ


I want to make replace & search functions in my text editor. Thanks to the
kind people here at the newsgroup, I was able to make the [REPLACE ALL]
But I was not able to understand how to REPLACE the next word (the nearest
word from the cursor; not REPLACE ALL, but replace only one word) and SEARCH
the next word.
COuld some one help me? Thanks in advance.

Nov 15 '05 #1
1 1682
Use the position of the cursor in the text string and find the first occurrence of the search word after that index:

String theText, searchWord, replaceWord;
int cursorPos;

// TODO:
// set the values for each variable above

int foundPos = theText.IndexOf (searchWord, cursorPos);

if (foundPos != -1) {
// if the word was found, copy the preceding text,
// sub the word and copy the trailing text

theText = theText.Substri ng(0, foundPos) + replaceWord +
theText.Substri ng(foundPos + searchWord.Leng th);
I hope this helps,
Nov 15 '05 #2

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

Similar topics

by: Zenobia | last post by:
Hello I want a search & replace text in source code for several files in several directories. It would seem that both Dreamweaver MX 6 and GoLive 6 offer this feature but not for .aspx file types. Is there a hack that sets the configuration files for one of these programs and fools the program into allowing the global search and replace?
by: tchurm | last post by:
Hi Pythonistas, Here's my problem: I'm using a version of MOOX Firefox (http://moox.ws/tech/mozilla/) that's been modified to run completely from a USB Stick. It works fine, except when I install or uninstall an extension, in which case I then have to physically edit the compreg.dat file in my profile directory, replacing all instances of Absolute Path links to relative ones. (And, yes, I have filed a Bugzilla report.) For example,...
by: Tomomichi Amano | last post by:
Could some one tell me how I can seach and replace only one word in a textBox (THE FIRST WORD THAT COMES AFTER THE CURSOR). I already know how to replace ALL , but I don't know how to REPLACE one, and how to SEARCH one and select that point. Thank in advance
by: Jan | last post by:
Hello! I am looking for a way to do a search&replace in ASCII-Files by a vb.net 2005 programm. Of coarse I can open the files, loop to every line, make a replace, and save the line. But I wonder if there is a better and faster way to do it. To make it clear: The search&replace must be done within a programm not in the Framework or editor.
by: Jon | last post by:
Hi, I have an arrayList that holds an ArrayObject with (Qty & ItemCode). e.g. arrayList.Add(New ArrayObject(Qty, ItemCode) However, I want to search the arrayList and check if the ItemCode already exist on the arrayList, then simply increase the Qty by 1. For example: I have in my arraylist:
by: DataSmash | last post by:
Hello, I need to search and replace 4 words in a text file. Below is my attempt at it, but this code appends a copy of the text file within itself 4 times. Can someone help me out. Thanks! # Search & Replace file = open("text.txt", "r") text = file.read()
by: Ola K | last post by:
Hi guys, I wrote a script that works *almost* perfectly, and this lack of perfection simply puzzles me. I simply cannot point the whys, so any help on it will be appreciated. I paste it all here, the string at the beginning explains what it does: '''A script for MS Word which does the following: 1) Assigns all Hebrew italic characters "Italic" character style. 2) Assigns all Hebrew bold characters "Bold" character style. 2) Assign all...
by: Proaccesspro | last post by:
I'm trying to create a search & replace function in Access. Specifically, I want to search for a specific SSN and replace it, if found. Not sure how to code the "guts" of it. Here is what I have so far: Private Sub CmdUpdateAppeal_Click() SSNreplace = InputBox("Please enter the Member's SSN", "Update a SSN") If SSNreplace = "" Then MsgBox "No Number Entered. Please Try Again", vbCritical, "Update a SSN" End End If
by: simon.robin.jackson | last post by:
Ok. I need to develop a macro/vba code to do the following. There are at least 300 corrections and its expected for this to happen a lot more in the future. Therefore id like a nice button that does this all for me. In my head the method should go something like this:
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...
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,...
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...
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,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.