473,382 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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 3479
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: /, \, :, *, ?, ", <, >, | I have it right now with string.replace for each...
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 leading whitespaces from the string. Tried this one...
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 string. while stepping through the code, RegEx...
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 write a regular expression that will do the...
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. Regex.Replace(inputString, ".*0\\.000000.*\n", ""); I...
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 code below. I have two questions. First, the...
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. ie *.doc dhows all doc *.* shows all...
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 a term (word or phrase) with a link. The pupose...
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 rewrite them without Regex? The most time-consuming...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.