472,333 Members | 1,103 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,333 software developers and data experts.

regex.replace and trim

bonjour hello

I would like to trim a string of all its white spaces so i used
myString.trim() but it doesn't work as supposed : unsecable space are
remaining in the middle of my string...
i read in msdn : and notice that trim only Removes all occurrences of white
space characters from the beginning and end of this instance. So what for
the middle ?

.NET Framework Class Library
String.Trim Method ()
Remarks
The following table lists the white space characters removed by the Trim
method. The first column lists the Unicode name for the character, and the
second column lists the Unicode hexadecimal notation for the code point that
identifies the character.

Unicode name
Unicode code point

CHARACTER TABULATION
U+0009

LINE FEED
U+000A

LINE TABULATION
U+000B

FORM FEED
U+000C

CARRIAGE RETURN
U+000D

SPACE
U+0020

NO-BREAK SPACE
U+00A0

EN QUAD
U+2000

EM QUAD
U+2001

EN SPACE
U+2002

EM SPACE
U+2003

THREE-PER-EM SPACE
U+2004

FOUR-PER-EM SPACE
U+2005

SIX-PER-EM SPACE
U+2006

FIGURE SPACE
U+2007

PUNCTUATION SPACE
U+2008

THIN SPACE
U+2009

HAIR SPACE
U+200A

ZERO WIDTH SPACE
U+200B

IDEOGRAPHIC SPACE
U+3000

ZERO WIDTH NO-BREAK SPACE
U+FEFF

But anything else for the middle than replace ?
perhaps something with regex.replace ?
Public Shared Function Replace ( _
input As String, _
pattern As String, _
replacement As String, _
options As RegexOptions _
) As String
Dim input As String
Dim pattern() As String 'is it possible to put an array of all white spaces
here ?Dim replacement As String
Dim options As RegexOptions
Dim returnValue As String

returnValue = Regex.Replace(input, pattern, replacement, options)
End FunctionDoes anyone know a good function for removing all theese kind of
space in my string ?
http://www.scalpa.info
Nov 5 '06 #1
3 3381
Go through the string and check each character.
The fastest way to do this is to use a
StringBuilder and append each valid character to it.

Public Function RemoveWhiteSpace(ByVal InputString As String) _
As String
Dim sb As New StringBuilder(InputString.Length)
For n As Integer = 0 To InputString.Length - 1
If Not IsWhiteSpace(InputString, n) Then
sb.Append(InputString.Substring(n, 1))
End If
Next
Return sb.ToString
End Function

You need to import System.Char for the IsWhiteSpace method,
and System.Text for the Stringbuilder class.

Robin S.

"Pascal" <sc*********@wanadoo.rfwrote in message
news:45***********************@news.orange.fr...
bonjour hello

I would like to trim a string of all its white spaces so i used
myString.trim() but it doesn't work as supposed : unsecable space are
remaining in the middle of my string...
i read in msdn : and notice that trim only Removes all occurrences of
white space characters from the beginning and end of this instance. So
what for the middle ?

.NET Framework Class Library
String.Trim Method ()
Remarks
The following table lists the white space characters removed by the Trim
method. The first column lists the Unicode name for the character, and the
second column lists the Unicode hexadecimal notation for the code point
that identifies the character.

Unicode name
Unicode code point

CHARACTER TABULATION
U+0009

LINE FEED
U+000A

LINE TABULATION
U+000B

FORM FEED
U+000C

CARRIAGE RETURN
U+000D

SPACE
U+0020

NO-BREAK SPACE
U+00A0

EN QUAD
U+2000

EM QUAD
U+2001

EN SPACE
U+2002

EM SPACE
U+2003

THREE-PER-EM SPACE
U+2004

FOUR-PER-EM SPACE
U+2005

SIX-PER-EM SPACE
U+2006

FIGURE SPACE
U+2007

PUNCTUATION SPACE
U+2008

THIN SPACE
U+2009

HAIR SPACE
U+200A

ZERO WIDTH SPACE
U+200B

IDEOGRAPHIC SPACE
U+3000

ZERO WIDTH NO-BREAK SPACE
U+FEFF

But anything else for the middle than replace ?
perhaps something with regex.replace ?
Public Shared Function Replace ( _
input As String, _
pattern As String, _
replacement As String, _
options As RegexOptions _
) As String
Dim input As String
Dim pattern() As String 'is it possible to put an array of all white
spaces here ?Dim replacement As String
Dim options As RegexOptions
Dim returnValue As String

returnValue = Regex.Replace(input, pattern, replacement, options)
End FunctionDoes anyone know a good function for removing all theese kind
of space in my string ?
http://www.scalpa.info

Nov 5 '06 #2
Whoa !!! It works fine.............Thanks a lot

Nov 5 '06 #3
trim does what it says, "trims" stuff off the start of end not the middle..
if it took from the middle that'd be a substring because it would take from
that point out

"Pascal" <sc*********@wanadoo.rfwrote in message
news:45***********************@news.orange.fr...
bonjour hello

I would like to trim a string of all its white spaces so i used
myString.trim() but it doesn't work as supposed : unsecable space are
remaining in the middle of my string...
i read in msdn : and notice that trim only Removes all occurrences of
white space characters from the beginning and end of this instance. So
what for the middle ?

.NET Framework Class Library
String.Trim Method ()
Remarks
The following table lists the white space characters removed by the Trim
method. The first column lists the Unicode name for the character, and the
second column lists the Unicode hexadecimal notation for the code point
that identifies the character.

Unicode name
Unicode code point

CHARACTER TABULATION
U+0009

LINE FEED
U+000A

LINE TABULATION
U+000B

FORM FEED
U+000C

CARRIAGE RETURN
U+000D

SPACE
U+0020

NO-BREAK SPACE
U+00A0

EN QUAD
U+2000

EM QUAD
U+2001

EN SPACE
U+2002

EM SPACE
U+2003

THREE-PER-EM SPACE
U+2004

FOUR-PER-EM SPACE
U+2005

SIX-PER-EM SPACE
U+2006

FIGURE SPACE
U+2007

PUNCTUATION SPACE
U+2008

THIN SPACE
U+2009

HAIR SPACE
U+200A

ZERO WIDTH SPACE
U+200B

IDEOGRAPHIC SPACE
U+3000

ZERO WIDTH NO-BREAK SPACE
U+FEFF

But anything else for the middle than replace ?
perhaps something with regex.replace ?
Public Shared Function Replace ( _
input As String, _
pattern As String, _
replacement As String, _
options As RegexOptions _
) As String
Dim input As String
Dim pattern() As String 'is it possible to put an array of all white
spaces here ?Dim replacement As String
Dim options As RegexOptions
Dim returnValue As String

returnValue = Regex.Replace(input, pattern, replacement, options)
End FunctionDoes anyone know a good function for removing all theese kind
of space in my string ?
http://www.scalpa.info

Nov 6 '06 #4

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

Similar topics

4
by: GregMa | last post by:
Does anyone have a good regex expression to replace any invalid filename characters in a string? Those characters are: /, \, :, *, ?, ", <, >, | ...
1
by: Andi Reisenhofer | last post by:
Hallo folks, Just started to use regex a bit with c#. Want to do the following perhaps somebody have a tip. 1) want to remove trailing and...
1
by: kevin | last post by:
I am trying to strip the outermost html tag by capturing this tag with regex and then using the string replace function to replace it with an empty...
2
by: Alex Maghen | last post by:
This is a bit of an abuse of this group. Just a nit, but I'm hoping someone really good with Regular Expressions can help me out here. I need to...
4
by: Morgan Cheng | last post by:
In my case, I have to remove any line containing "0.000000" from input string. In below case, it takes about 100 ms for 2k size input string....
3
by: jwgoerlich | last post by:
Hello group, I am working on a query string class. The purpose is to parse name-value pairs from incoming text. Currently, I am using the Regex...
2
by: Jeff Williams | last post by:
I have a list of file names I need to parse and check if they match a valid expression. I want this to work like you were listing a directory. ...
1
by: jonnyboy6969 | last post by:
Hi All Really hoping someone can help me out here with my deficient regex skills :) I have a function which takes a string of HTML and replaces...
0
by: Karch | last post by:
I have these two methods that are chewing up a ton of CPU time in my application. Does anyone have any suggestions on how to optimize them or...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

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.