473,761 Members | 10,684 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Replacing Text without changing case??

RE: Replacing Text without changing case??

This code works great, but case has to be exact.

Research.Text = Research.Text.R eplace(textboxS earch.Text, "<b>" +
textboxSearch.T ext + "</b>")

I found some c# code, but I can't make it work in vb.net:

Regex.Replace(R esearch.Text, textboxSearch.T ext, New
MatchEvaluator( HiLite), RegexOptions.Ig noreCase)
....
Public Shared Function HiLite(ByVal match As Match) As String
Return "<b>" + match.Value + "</b>*"
End Function
Its complaining about Hilite in the first line.
Mar 6 '08 #1
4 1859
THANK YOU!

Regex.Replace(s tring.format("( {0})", Regex.Escape(in put)), "<b>$1</b>", RegexOptions.Ig noreCase)
Presuming

user search input : textboxSearch.t ext
replace is : "<b>"+textboxSe arch.text+"</b>"
data I'm looking to impact is : Research.Text (a gridview row label
control)
How would I use the above?

I tried:

Imports System.Text.Reg ularExpressions

Research.Text = Regex.Replace(S tring.Format("( {0})",
Regex.Escape(te xtboxSearch.Tex t)), "<b>$1</b>",
RegexOptions.Ig noreCase)
Getting an error on Regex.Replace : Reference to a non-shared member
requires an object reference.

So I noticed it appears to be formated incorrectly and probably should
be :

Research.Text = Regex.Replace(S tring.Format("( {0})"),
Regex.Escape(te xtboxSearch.Tex t), "<b>$1</b>",
RegexOptions.Ig noreCase)

However that did not work.

I also tried:
No effect:
Research.Text = Regex.Replace(S tring.Format("( {0})"),
Regex.Escape(te xtboxSearch.Tex t), "<b>$1</b>",
RegexOptions.Ig noreCase)
replaces string with actually "$1":
'Research.Text = Regex.Replace(R esearch.Text,
Regex.Escape(te xtboxSearch.Tex t), "<b>$1</b>",
RegexOptions.Ig noreCase)
works, in finding the strings, but replaces with wrong case:
'Research.Text = Regex.Replace(R esearch.Text,
Regex.Escape(te xtboxSearch.Tex t), "<b>"+ textboxSearch.T ext+"</b>",
RegexOptions.Ig noreCase)

Thanks again.


Mar 7 '08 #2
Hello wi*****@noclien t.net,
THANK YOU!
>Regex.Replace( string.format(" ({0})", Regex.Escape(in put)),
"<b>$1</b>", RegexOptions.Ig noreCase)
Presuming

user search input : textboxSearch.t ext
replace is : "<b>"+textboxSe arch.text+"</b>"
data I'm looking to impact is : Research.Text (a gridview row label
control)
How would I use the above?

I tried:

Imports System.Text.Reg ularExpressions

Research.Text = Regex.Replace(S tring.Format("( {0})",
Regex.Escape(te xtboxSearch.Tex t)), "<b>$1</b>",
RegexOptions.Ig noreCase)

Getting an error on Regex.Replace : Reference to a non-shared member
requires an object reference.

So I noticed it appears to be formated incorrectly and probably should
be :

Research.Text = Regex.Replace(S tring.Format("( {0})"),
Regex.Escape(te xtboxSearch.Tex t), "<b>$1</b>",
RegexOptions.Ig noreCase)

However that did not work.

I also tried:

No effect:
Research.Text = Regex.Replace(S tring.Format("( {0})"),
Regex.Escape(te xtboxSearch.Tex t), "<b>$1</b>",
RegexOptions.Ig noreCase)
replaces string with actually "$1":
'Research.Text = Regex.Replace(R esearch.Text,
Regex.Escape(te xtboxSearch.Tex t), "<b>$1</b>",
RegexOptions.Ig noreCase)
works, in finding the strings, but replaces with wrong case:
'Research.Text = Regex.Replace(R esearch.Text,
Regex.Escape(te xtboxSearch.Tex t), "<b>"+ textboxSearch.T ext+"</b>",
RegexOptions.Ig noreCase)
Sorry, I mixed the input and the pattern parameters to the Regex.Replace
function.

This should do it (in C#, I'm no star in VB):

string input = "a.b.c.d.e.f.g. h.i.j";
string output = Regex.Replace(i nput, string.Format(" ({0})", Regex.Escape(in put)),
"<b>$1</b>");
Console.WriteLi ne(output);

--
Jesse Houwing
jesse.houwing at sogeti.nl
Mar 7 '08 #3
I'm close, but this ends up highighting all of research.text when a
match is found. How can I highlight just the found string in it's
original case?

Research.Text = Regex.Replace(R esearch.Text, String.Format(" ({0})",
Regex.Escape(Re search.Text)), "<FONT style='backgrou nd-color:Yellow'>
$1</FONT>")

thanks.
Mar 12 '08 #4
Hello wi*****@noclien t.net,
I'm close, but this ends up highighting all of research.text when a
match is found. How can I highlight just the found string in it's
original case?

Research.Text = Regex.Replace(R esearch.Text, String.Format(" ({0})",
Regex.Escape(Re search.Text)), "<FONT style='backgrou nd-color:Yellow'>
$1</FONT>")
That shouldn't be too hard, but currently you're puttign the whole string
in for both input and pattern.
Research.Text = Regex.Replace(
Research.Text, <== input
String.Format(" ({0})", Regex.Escape(Re search.Text)), <== text to search
"<FONT style='backgrou nd-color:Yellow'>$ 1</FONT>" <== replacement
)

So make sure you only put the text to search in the correct place.

--
Jesse Houwing
jesse.houwing at sogeti.nl
Mar 14 '08 #5

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

Similar topics

13
15255
by: yaipa | last post by:
What would be the common sense way of finding a binary pattern in a ..bin file, say some 200 bytes, and replacing it with an updated pattern of the same length at the same offset? Also, the pattern can occur on any byte boundary in the file, so chunking through the code at 16 bytes a frame maybe a problem. The file itself isn't so large, maybe 32 kbytes is all and the need for speed is not so great, but the need for accuracy in the...
13
4807
by: Eddie | last post by:
I need to validate a text input field. I just want to say if user enters 93101 or 93102 or 93103 or 93105 or 93106 or 93107 or 93108 or 93109 or 93110 or 93111 or 93116 or 93117 or 93118 or 93120 or 93121 or 93130 or 93140 or 93150 or 93160 or 93190 or 93199 or 93199 or 93401 or 93402 or 93403 or 93405 or 93406 or 93407 or 93408 or 93409 or 93410 or 93412
11
5158
by: Peter Foti | last post by:
Hi all, I have a form that contains a 2 column table. In the left column is the description for a particular input (ie - "First Name", "Last Name", "Phone Number", etc.). In the right column is the input element. The left column is right aligned and the right column is left aligned. I would like to replace this table with code that does not use a table for layout, and was hoping someone might be able to help me with the HTML and...
3
2253
by: dornick | last post by:
So I want to do the above, and I really, REALLY don't want to rewrite the entire file. I've been working on it for a while now, and can't for the life of me get it functioning. Basically, I want to replace the last text character of a certain line. So far all I've done has centered around trying to put the "put" pointer write before the character to write (ban pun, I know). But when I tried to use put(), nothing happened and a call to...
7
21703
by: VMI | last post by:
If I have the string "Héllo", how can I replace char (é) with an 'e'? I cannot use the String.Replace() fuction. It has to be by replacing one char with another. Thanks.
1
1352
by: Andy Roxburgh | last post by:
Hi, I have an monitoring application that displays various pieces of data, which are changing, on a tabpage within a form. The data is displayed in various different colours and the various items are shown in different positions on the form. It's a status panel basically. I'm originally used labels to hold all the various bits of text. I don't want to use labels because: (1) I'm using the .Net Compact Framework which only allows...
7
2624
by: Daniel Kabs | last post by:
Hi there, for a long time I've been using tables to layout elements on a web page. Example: Say we have a 2x2 table and I'd like to put text (left aligned) and buttons (right aligned) in the top right table cell. These elements should stay on one line and the table should keep a minimum width in order to prevent wrapping. -------------------------------------------------
2
6545
by: David | last post by:
Sent this to alt.php a couple of days back, but doesn't look like I'll get an answer, so trying here. I'm trying to convert a script to use friendly URLs, I've done this before, but my PHP skills are quite basic so far, far from proficient at this. ..htaccess file- DirectoryIndex default.php index.asp index.html index.htm index.php
1
2651
by: TamusJRoyce | last post by:
I have xsl code which I was hoping could be used to replace one specific tag from an xhtml document and output another xhtml document. xsl has phenomenal potential in data replacing, but coming from C/C++ background, it looks like a functional language I'm not familiar with. Here's the link to where I got the code (thanks goes to the author), but I don't have a strong enough background in xsl to tell what is going on. xslfile.xsl ...
0
9333
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
10107
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...
1
9900
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
9765
tracyyun
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...
1
7324
isladogs
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...
0
6599
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
5214
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...
1
3863
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2733
bsmnconsultancy
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.