473,320 Members | 1,969 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,320 software developers and data experts.

VB.NET String Manipulation similar to RegularExpresion

Hi,

Does anyone knows any good code for string manipulation similar to
RegularExpresion?

I might get a value as string in a different format. Example:

20/02/2006 or 20,02,2006 or 20.02.2006 etc...

And I want to replace the /,.etc character with - (as 20-02-2006)

The VB.NET replace operation can replace single character at a time. What I
need is similar to RegularExpresion that I might code a sinle line as:

Dim mySTR as String = ""
mySTR = CStr(TableTAK.Rows(i))

Dim myCurDate as String = ""
myCurDate = mySTR.xReplace("/,.", "-")

The function that I need (xReplace) will replace any character "/,." in
mySTR with character "-".

The xReplace function might allow me to assign any character that I want to
replace. Not just 3 character that I desribe in above.

I know I have to create a function to do but I am looking for much faster
way doing that like in RegularExpresion.

I thank you in advance for reading my post.

Rgds,
GC

Aug 2 '06 #1
5 7435
Niyazi <Ni****@discussions.microsoft.comwrote:
Does anyone knows any good code for string manipulation similar to
RegularExpresion?
Any reason not to just use System.Text.RegularExpressions?

<snip>
I know I have to create a function to do but I am looking for much faster
way doing that like in RegularExpresion.
I suspect that for reasonably small numbers of replacement characters,
using the straight String.Replace method will be faster than using
regular expressions, actually. If you really care about performance,
you should certainly measure it.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 2 '06 #2
Hi Jon,

The String.Replace it allows me to replace one character at a time and I
have to code 3 line for each character. What I was looking for to replace the
more than one character if its found in string with the second character.

String.Replace("/|*|.|,", "-")

As you may see I need to replace the / * . , character with -
But String.Replace doesnot allow me to use more than one character. On the
other hand the RegularExpresion cannot allow me to use some character that I
need to be replaced.

So I guess I have to use my own function to do that. I wish I can manipulate
with overloading the String.Replace but unfortunatly I don't know how.

Thank you for your input.

Rgds,
GC

"Jon Skeet [C# MVP]" wrote:
Niyazi <Ni****@discussions.microsoft.comwrote:
Does anyone knows any good code for string manipulation similar to
RegularExpresion?

Any reason not to just use System.Text.RegularExpressions?

<snip>
I know I have to create a function to do but I am looking for much faster
way doing that like in RegularExpresion.

I suspect that for reasonably small numbers of replacement characters,
using the straight String.Replace method will be faster than using
regular expressions, actually. If you really care about performance,
you should certainly measure it.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 3 '06 #3
Niyazi <Ni****@discussions.microsoft.comwrote:
The String.Replace it allows me to replace one character at a time and I
have to code 3 line for each character. What I was looking for to replace the
more than one character if its found in string with the second character.

String.Replace("/|*|.|,", "-")
You've just demonstrated why using regular expressions is dangerous -
more later.
As you may see I need to replace the / * . , character with -
But String.Replace doesnot allow me to use more than one character. On the
other hand the RegularExpresion cannot allow me to use some character that I
need to be replaced.

So I guess I have to use my own function to do that. I wish I can manipulate
with overloading the String.Replace but unfortunatly I don't know how.
Yes, you'd have to write your own helper method which went through an
array of characters and called String.Replace on each of them. The good
thing about this is that it's incredible simple. The bad thing is that
as the number of characters to replace increases, so does the time
taken.

The bad thing about regular expressions is that they're complicated.
The expression /|*|.|, doesn't match a single slash, a single star, a
single dot or a single comma - because dot and star have specific
meanings in regular expressions. You need to be very, very careful.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 3 '06 #4
Niyazi wrote:
As you may see I need to replace the / * . , character with -
But String.Replace doesnot allow me to use more than one character. On the
other hand the RegularExpresion cannot allow me to use some character that I
need to be replaced.
Sure it does.

Regex.Replace(Text, "[/*.]", "-");

// match any of the three characters /, *, or .
// replace all matches with "-".

--

..NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn In print, in stores.
Aug 3 '06 #5
Hi Jon Shemitz,

Thank you for your input. It did worked when use [] character.
I thank you very much.

Rgds,
GC

"Jon Shemitz" wrote:
Niyazi wrote:
As you may see I need to replace the / * . , character with -
But String.Replace doesnot allow me to use more than one character. On the
other hand the RegularExpresion cannot allow me to use some character that I
need to be replaced.

Sure it does.

Regex.Replace(Text, "[/*.]", "-");

// match any of the three characters /, *, or .
// replace all matches with "-".

--

..NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn In print, in stores.
Aug 7 '06 #6

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

Similar topics

12
by: Eli Daniel | last post by:
Hi, I'm new to Python. Can you please tell me if the following is possible. My users are using other scripting launguage to write scripts. They are used to write somthing like (keeping it...
16
by: zohaibbaloch | last post by:
how to manipulate string without using arrays.manipulation example i have to print dog or any string i want to cut d from dog and paste it a end and add a at the last dog becoms ogda. please...
3
by: Amintas | last post by:
Hi Everybody, Can anyone please tell me how I can get the rightmost characters of a string? In Visual Basic .NET there is still the old-fashioned but handy "right()" function. Since C# does...
5
by: BILL | last post by:
Hi Everyone, I've been looking through these .NET groups and can't find the exact answer I want, so I'm asking. Can someone let me know the best way (you feel) to search a C# string for an...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
7
by: John A Grandy | last post by:
what are the preferred VB.NET analogues for IsNumeric() and Len() and CInt() & similar string-manipulation functions in VB6
20
by: bubunia2000 | last post by:
Hi all, I heard that strtok is not thread safe. So I want to write a sample program which will tokenize string without using strtok. Can I get a sample source code for the same. For exp:...
4
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if...
8
by: John Salerno | last post by:
Ok, for those who have gotten as far as level 2 (don't laugh!), I have a question. I did the translation as such: import string alphabet = string.lowercase code = string.lowercase + 'ab'...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.