473,683 Members | 3,757 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB.NET String Manipulation similar to RegularExpresio n

Hi,

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

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 RegularExpresio n that I might code a sinle line as:

Dim mySTR as String = ""
mySTR = CStr(TableTAK.R ows(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 RegularExpresio n.

I thank you in advance for reading my post.

Rgds,
GC

Aug 2 '06 #1
5 7482
Niyazi <Ni****@discuss ions.microsoft. comwrote:
Does anyone knows any good code for string manipulation similar to
RegularExpresio n?
Any reason not to just use System.Text.Reg ularExpressions ?

<snip>
I know I have to create a function to do but I am looking for much faster
way doing that like in RegularExpresio n.
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.co m>
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 RegularExpresio n 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****@discuss ions.microsoft. comwrote:
Does anyone knows any good code for string manipulation similar to
RegularExpresio n?

Any reason not to just use System.Text.Reg ularExpressions ?

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

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.co m>
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****@discuss ions.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 RegularExpresio n 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.co m>
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 RegularExpresio n cannot allow me to use some character that I
need to be replaced.
Sure it does.

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

// 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 RegularExpresio n cannot allow me to use some character that I
need to be replaced.

Sure it does.

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

// 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
1625
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 simple) T = 100 do_action ('It cost $T dollars')
16
382
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 help
3
1382
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 not support these old stuff, I could not find anything similar. My guess is that there must be a way to do it by using any method of the String class. Thanks a lot,
5
14908
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 occurance of a CASE INSENSITIVE substring, returning the found position. I'm speaking of larger strings to search as well ~50K-500K. Here's what I have so far:
32
14847
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 ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
7
11587
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
17212
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: 0.0.0.0--->I want to tokenize the string using delimiter as as dot. Regards
4
3481
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 substrings need be replaced, or one character needs be changed, what shall I do? Is it better to convert strings to UCS-32 before manipulation? But on Windows, wchar_t is 16 bits which isn't enough for characters which can't be simply encoded...
8
2259
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' clue = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."
0
8568
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
9043
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
8753
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,...
1
6429
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
5789
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
4299
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...
0
4519
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2934
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
2
2195
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.