473,725 Members | 2,232 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems with Replace Method

Hi, I am loading a CSV file ( Comma Seperated Value) into a Richtext box. I have a routine that splits the data up when it hits
the "," and then copies the results into a listbox. The data also has some different characters in it that I am trying to
remove. The small a with two dots over it and the small y with two dots over it. Here is my code so far to remove the small y:

Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button2.Click

'cleans the "," character out of a comma delimited string and outputs the results to a listbox

Dim str As String = RichTextBox1.Te xt

Dim x As String = Chr(255) 'Chr(255)

Dim arr() As String = str.Split(","c)

'Dim arr() As String = str.Split(Chr(2 55), c)

For Each s As String In arr

' s = Replace(Chr(255 ), Chr(32),)

For Each x In s

s.Replace(x, Chr(32))

Next

ListBox1.Items. Add(s)

Next

End Sub

The problem is, when I put a Breakpoint on ListBox1.Items. Add(s), I can step into the code as it goes thru the data from the
Richtextbox and it shows the value for X as being = """" instead of the y with the two dots over it! Therefore instead of
replacing the y with a Space ( Chr(32) , it does nothing! I have checked to be sure I am using the right character code and
that part is correct. ( I tested by setting a labels text property to : Chr(255) and it displayed correctly.)

I know that I am doing something wrong , I just cannot see what it is.

Any suggestions would be greatly appreciated.

james



Nov 21 '05 #1
18 4624
On Fri, 12 Nov 2004 16:17:53 -0600, james wrote:
s.Replace(x, Chr(32))


This line will not replace anything, you must assign the result back to the
string:

s = s.Replace(x,Chr (32))

--
Chris

dunawayc[AT]sbcglobal_lunch meat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #2
On Fri, 12 Nov 2004 16:17:53 -0600, james wrote:
s.Replace(x, Chr(32))


This line will not replace anything, you must assign the result back to the
string:

s = s.Replace(x,Chr (32))

--
Chris

dunawayc[AT]sbcglobal_lunch meat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #3
Chris, thanks for the suggestion, however, that just replaces all the text with a space " " .
What I am having a problem with is that the value of X that I define as Chr(255) ,,, which is supposed to be the small y with
two dots over it, has am empty value instead of the intended value. I don't understand how X 's value is being changed as I
have set it at one value and for whatever reason it becomes another.
I thought that maybe, I was actually using the wrong Chr value for the little y with the two dots above.
But, I cannot find any reference in Help (VB.NET 2003) that shows what the character values are. There is no table(s) in the
docs that I can find like my old VB6 reference library that had the ANSI character sets listed with the correct Chr(numbers)
listed that I can use to define the character I need to find and replace using Chr or ChrW. I think that is the problem.
VB.NET , since it uses Unicode for Characters, is not reading the correct value for X. Even though I can display that value and
character using Chr(255) on a label and it will show the correct character.
I'm getting cross-eyed (hard for a one eyed guy to do) looking for this reference and the solution to what should be a simple
problem.
james

"Chris Dunaway" <"dunawayc[[at]_lunchmeat_sbcg lobal[dot]]net"> wrote in message
news:1v******** *************** *******@40tude. net...
On Fri, 12 Nov 2004 16:17:53 -0600, james wrote:
s.Replace(x, Chr(32))


This line will not replace anything, you must assign the result back to the
string:

s = s.Replace(x,Chr (32))

--
Chris

dunawayc[AT]sbcglobal_lunch meat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.

Nov 21 '05 #4
Chris, thanks for the suggestion, however, that just replaces all the text with a space " " .
What I am having a problem with is that the value of X that I define as Chr(255) ,,, which is supposed to be the small y with
two dots over it, has am empty value instead of the intended value. I don't understand how X 's value is being changed as I
have set it at one value and for whatever reason it becomes another.
I thought that maybe, I was actually using the wrong Chr value for the little y with the two dots above.
But, I cannot find any reference in Help (VB.NET 2003) that shows what the character values are. There is no table(s) in the
docs that I can find like my old VB6 reference library that had the ANSI character sets listed with the correct Chr(numbers)
listed that I can use to define the character I need to find and replace using Chr or ChrW. I think that is the problem.
VB.NET , since it uses Unicode for Characters, is not reading the correct value for X. Even though I can display that value and
character using Chr(255) on a label and it will show the correct character.
I'm getting cross-eyed (hard for a one eyed guy to do) looking for this reference and the solution to what should be a simple
problem.
james

"Chris Dunaway" <"dunawayc[[at]_lunchmeat_sbcg lobal[dot]]net"> wrote in message
news:1v******** *************** *******@40tude. net...
On Fri, 12 Nov 2004 16:17:53 -0600, james wrote:
s.Replace(x, Chr(32))


This line will not replace anything, you must assign the result back to the
string:

s = s.Replace(x,Chr (32))

--
Chris

dunawayc[AT]sbcglobal_lunch meat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.

Nov 21 '05 #5
Fixed it!!!!!!!!!
For anyone interested (besides me) here's what I did:

Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button2.Click

'cleans the "," character out of a comma delimited string and outputs the results to a listbox

Dim str As String = RichTextBox1.Te xt

Dim x As String = Chr(255)

Dim arr() As String = str.Split(","c)

For Each s As String In arr

' the routine below looks for Chr(255) in the string s and then if it's there, replaces it with a space, if it's not there then
it just adds 'the original character to the string
If InStr(s, x) Then

s = s.Replace(x, Chr(32))

Else

s = s

End If

ListBox1.Items. Add(s)

Next

End Sub


Nov 21 '05 #6
Fixed it!!!!!!!!!
For anyone interested (besides me) here's what I did:

Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button2.Click

'cleans the "," character out of a comma delimited string and outputs the results to a listbox

Dim str As String = RichTextBox1.Te xt

Dim x As String = Chr(255)

Dim arr() As String = str.Split(","c)

For Each s As String In arr

' the routine below looks for Chr(255) in the string s and then if it's there, replaces it with a space, if it's not there then
it just adds 'the original character to the string
If InStr(s, x) Then

s = s.Replace(x, Chr(32))

Else

s = s

End If

ListBox1.Items. Add(s)

Next

End Sub


Nov 21 '05 #7
James,
I use Character Map under "Programs - Accessories - System Tools" on Windows
XP.

If you select a character you can look in the lower left hand corner for the
Unicode code point (which is displayed in hex). For example the Latin Small
Letter Y With Diaeresis (ÿ) is U+00FF which in VB.NET you can use:

Const LatinSmallLette rYWithDiaeresis As Char = ChrW(&HFF)

It just happens that in the US (& most of Europe) that the ANSI code point
is the same 255 or &HFF. However there are a number of characters, such as
Left Double Quote " that the code points are different.

Const LeftDoubleQuote As Char = ChrW(&H201C) ' Ansi = 147
Const RightDoubleQuot e As Char = ChrW(&H201D) ' Ansi = 148

I almost always use ChrW & the Unicode code points as Chr & the Ansi code
points can be effected by the region settings in Control Panel. ChrW(&HFF)
will be a ÿ no matter where you go, where as Chr(&HFF) may be some other
character in other countries...

Hope this helps
Jay

"james" <jjames700ReMoV eMe at earthlink dot net> wrote in message
news:uF******** ******@TK2MSFTN GP14.phx.gbl...
Chris, thanks for the suggestion, however, that just replaces all the text
with a space " " .
What I am having a problem with is that the value of X that I define as
Chr(255) ,,, which is supposed to be the small y with two dots over it,
has am empty value instead of the intended value. I don't understand how
X 's value is being changed as I have set it at one value and for whatever
reason it becomes another.
I thought that maybe, I was actually using the wrong Chr value for the
little y with the two dots above.
But, I cannot find any reference in Help (VB.NET 2003) that shows what the
character values are. There is no table(s) in the docs that I can find
like my old VB6 reference library that had the ANSI character sets listed
with the correct Chr(numbers) listed that I can use to define the
character I need to find and replace using Chr or ChrW. I think that is
the problem. VB.NET , since it uses Unicode for Characters, is not reading
the correct value for X. Even though I can display that value and
character using Chr(255) on a label and it will show the correct
character.
I'm getting cross-eyed (hard for a one eyed guy to do) looking for this
reference and the solution to what should be a simple problem.
james

"Chris Dunaway" <"dunawayc[[at]_lunchmeat_sbcg lobal[dot]]net"> wrote in
message news:1v******** *************** *******@40tude. net...
On Fri, 12 Nov 2004 16:17:53 -0600, james wrote:
s.Replace(x, Chr(32))


This line will not replace anything, you must assign the result back to
the
string:

s = s.Replace(x,Chr (32))

--
Chris

dunawayc[AT]sbcglobal_lunch meat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.


Nov 21 '05 #8
James,
I use Character Map under "Programs - Accessories - System Tools" on Windows
XP.

If you select a character you can look in the lower left hand corner for the
Unicode code point (which is displayed in hex). For example the Latin Small
Letter Y With Diaeresis (ÿ) is U+00FF which in VB.NET you can use:

Const LatinSmallLette rYWithDiaeresis As Char = ChrW(&HFF)

It just happens that in the US (& most of Europe) that the ANSI code point
is the same 255 or &HFF. However there are a number of characters, such as
Left Double Quote " that the code points are different.

Const LeftDoubleQuote As Char = ChrW(&H201C) ' Ansi = 147
Const RightDoubleQuot e As Char = ChrW(&H201D) ' Ansi = 148

I almost always use ChrW & the Unicode code points as Chr & the Ansi code
points can be effected by the region settings in Control Panel. ChrW(&HFF)
will be a ÿ no matter where you go, where as Chr(&HFF) may be some other
character in other countries...

Hope this helps
Jay

"james" <jjames700ReMoV eMe at earthlink dot net> wrote in message
news:uF******** ******@TK2MSFTN GP14.phx.gbl...
Chris, thanks for the suggestion, however, that just replaces all the text
with a space " " .
What I am having a problem with is that the value of X that I define as
Chr(255) ,,, which is supposed to be the small y with two dots over it,
has am empty value instead of the intended value. I don't understand how
X 's value is being changed as I have set it at one value and for whatever
reason it becomes another.
I thought that maybe, I was actually using the wrong Chr value for the
little y with the two dots above.
But, I cannot find any reference in Help (VB.NET 2003) that shows what the
character values are. There is no table(s) in the docs that I can find
like my old VB6 reference library that had the ANSI character sets listed
with the correct Chr(numbers) listed that I can use to define the
character I need to find and replace using Chr or ChrW. I think that is
the problem. VB.NET , since it uses Unicode for Characters, is not reading
the correct value for X. Even though I can display that value and
character using Chr(255) on a label and it will show the correct
character.
I'm getting cross-eyed (hard for a one eyed guy to do) looking for this
reference and the solution to what should be a simple problem.
james

"Chris Dunaway" <"dunawayc[[at]_lunchmeat_sbcg lobal[dot]]net"> wrote in
message news:1v******** *************** *******@40tude. net...
On Fri, 12 Nov 2004 16:17:53 -0600, james wrote:
s.Replace(x, Chr(32))


This line will not replace anything, you must assign the result back to
the
string:

s = s.Replace(x,Chr (32))

--
Chris

dunawayc[AT]sbcglobal_lunch meat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.


Nov 21 '05 #9
Thank you Jay. I guess I have been spoiled by having VB6's Reference Library and now that I am using VB.NET (nope I did not thow
away the VB6 Ref. Library) I find it hard to understand why the character sets are not listed in Help, where they can easily be
found.
As you have probably seen from my previous posts in this thread, I am working on a utility to filter out
ANSI characters from a CSV file. I have that working fine as of now. But, the problem I have run into now is when I open the
file(CSV) with Access as a Text file with a Delimiter "," it parses the file just fine but, more of the extra characters appear
in some of the text in the datagrid I display the data in.
I can use a program called Textpad, to view the original file (the one I filtered) and it does not show the extra characters. I
can go into Access 2003 itself, and build a new database and import that same file
and under the Advanced setting, I can select UTF-8 and Access will import the CSV file correctly and without the extra
characters. But, my utility has a function that I am working on to build a new Access database using the CSV file's info and
when I load the file into the datagrid using this routine:

Private Sub btnImportCSV_Cl ick(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnImportCSV.Cl ick

DataGrid1.DataS ource = Nothing

Dim strFileName As String

Dim strFilePath As String

Dim sSlash As Single

Try

With OpenFileDialog1

..Title = "Import CSV file"

'.InitialDirect ory = "C:\"

..Filter = "File (*.xls;*.csv;*. txt)|*.xls;*.cs v;*.txt|All files (*.*)|*.*"

..FileName = ""

..ShowDialog()

sSlash = InStrRev(.FileN ame, "\")

strFilePath = Mid(.FileName, 1, sSlash)

strFileName = Mid(.FileName, sSlash + 1, Len(.FileName))

End With

Dim strConnectionSt ring As String = "Provider=Micro soft.Jet.OLEDB. 4.0;" _

& "Data Source=" & strFilePath & ";" _

& "Extended Properties=""te xt;HDR=Yes;FMT= Delimited\"""

Dim conn As New OleDb.OleDbConn ection(strConne ctionString)

conn.Open() ' Open connection with the database.

Dim objCmdSelect As New OleDb.OleDbComm and("SELECT * FROM [" & strFileName & "]", conn) .

' Create new OleDbDataAdapte r that is used to build a DataSet based on the preceding SQL SELECT statement.

Dim objAdapter1 As New OleDb.OleDbData Adapter

objAdapter1.Sel ectCommand = objCmdSelect 'Pass the Select command to the adapter.

Dim objDataset1 As New DataSet 'Create new DataSet to hold information from the worksheet.

Dim mytablename As String

objAdapter1.Fil l(objDataset1, "mytable") 'Fill the DataSet with the information from the file.

DataGrid1.DataS ource = objDataset1.Tab les(0).DefaultV iew 'Build a table from the original data.

TextBox1.Text = objDataset1.Tab les(0).Columns. Count

TextBox2.Text = objDataset1.Tab les(0).TableNam e

TextBox3.Text = objDataset1.Tab les(0).Rows.Cou nt.ToString

conn.Close() 'Clean up objects.

Catch ex As Exception

MsgBox(ex.Messa ge).ToString()

End Try

DataGrid1.Visib le = True

DataGrid1.Refre sh()

Me.Text = "Importing CSV File:" & strFileName

End Sub

I get the extra characters displayed in the datagrid. So, I know that the extra characters are not actually in the new CSV file
that I saved but, are being displayed by Access in some way.

Any suggestions on what I may be doing wrong here would be appreciated.

james


"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
James,
I use Character Map under "Programs - Accessories - System Tools" on Windows XP.

If you select a character you can look in the lower left hand corner for the Unicode code point (which is displayed in hex).
For example the Latin Small Letter Y With Diaeresis (ÿ) is U+00FF which in VB.NET you can use:

Const LatinSmallLette rYWithDiaeresis As Char = ChrW(&HFF)

It just happens that in the US (& most of Europe) that the ANSI code point is the same 255 or &HFF. However there are a number
of characters, such as Left Double Quote " that the code points are different.

Const LeftDoubleQuote As Char = ChrW(&H201C) ' Ansi = 147
Const RightDoubleQuot e As Char = ChrW(&H201D) ' Ansi = 148

I almost always use ChrW & the Unicode code points as Chr & the Ansi code points can be effected by the region settings in
Control Panel. ChrW(&HFF) will be a ÿ no matter where you go, where as Chr(&HFF) may be some other character in other
countries...

Hope this helps
Jay

Nov 21 '05 #10

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

Similar topics

12
8160
by: Barnes | last post by:
Does anyone know of a good way to use the JavaScript string.replace() method in an ASP form? Here is the scenario: I have a form that cannot accept apostrophes. I want to use the replace() so that the apostrophe is automatically replace with two '' . Reason being--SQL Server does not like apostrophes being sent to database. I've tried to do this on the server side in the SQL area of the ASP page by writing a function (with some great...
12
5938
by: Justin Koivisto | last post by:
I am having a problem with Internet Explorer and javascript on a WYSIWYG editor I am creating. It all works in Mozilla, but IE returns flase for queryCommandEnabled('forecol'). JS isn't my strong suit, so I am turning to all you experts for help. What am I missing here? Other commands like formatblock, fontsize and fontname all work fine, so I assume that it has something to do with not getting the correct selection because of the iframe....
3
3159
by: daveland | last post by:
I am working on some JavaScript that dynamically adds rows to a table in response to a button click. A new row does appear on the screen when the button is clicked. However, that table to which a row has been added is itself contained within an outer table (to handle the desired screen layout). That outer table does not properly grow to contain the new size of the table to which the row was added. (More specifically, I have...
2
2426
by: Barnes | last post by:
Hi, Can anyone please tell me how I can use the replace method to replace a character if it occures in more than one textbox without having to write separate function for each textbox. The code below is the basic way to use the replace method but it only allows for one textbox. I'm sure I need a loop in there but I'm not sure how to use that
4
3851
by: Cor | last post by:
Hi Newsgroup, I have given an answer in this newsgroup about a "Replace". There came an answer on that I did not understand, so I have done some tests. I got the idea that someone said, that the split method and the regex.replace method was better than the string.replace method and replace function. I did not believe that.
13
3319
by: bussiere bussiere | last post by:
hi i'am making a program for formatting string, or i've added : #!/usr/bin/python # -*- coding: utf-8 -*- in the begining of my script but str = str.replace('Ç', 'C') str = str.replace('é', 'E')
1
3407
by: NvrBst | last post by:
I want to use the .replace() method with the regular expression /^ %VAR % =,($|&)/. The following DOESN'T replace the "^default.aspx=,($|&)" regular expression with "": --------------------------------- myStringVar = myStringVar.replace("^" + iName + "=,($|&)", ""); --------------------------------- The following DOES replace it though: --------------------------------- var match = myStringVar.match("^" + iName + "=,($|&)");
1
2223
by: =?Utf-8?B?Q2hyaXN0aWFuIFdlaW5lcnQ=?= | last post by:
Hello, I currently fight with a problem during the derivative of WinForm controls. In Visual Studio I created a new User Control. This control is derived from the DataGridView of the System.Windows.Forms namespace. I want to use this control as a template for futher controls. Within this control i want to set some property values to be pre-defined for further derived controls. My base class looks like this:
10
2829
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, i have text like this: "ACPI\GENUINEINTEL_-_X86_FAMILY_6_MODEL_13\_0" an after displaying it in a RichTextBox as RTF string, i get this: "ACPI_-_x86_Family_6_Model_13 "
0
8888
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
8752
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
9257
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...
0
8097
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...
1
6702
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
6011
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
4519
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
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
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.