473,587 Members | 2,258 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Advanced String Manipulation (C#)

I would like to randomly output phone numbers seperated by \ and / from a string.
s = "\231-3423/\453-1234/\231-3473/\231-3474/"

//c sharp code
private string GetPhoneNum()
{
s = "\231-3423/\453-1234/\231-3473/\231-3474/"
//randomly pick a phone num from string.

n = randomNum;
return n;//ie. 453-1234
}

Thanks
Nov 18 '05 #1
2 1958
Hi Aaron,
I would like to randomly output phone numbers seperated by \ and / from a string. s = "\231-3423/\453-1234/\231-3473/\231-3474/"

//c sharp code
private string GetPhoneNum()
{
s = "\231-3423/\453-1234/\231-3473/\231-3474/"
//randomly pick a phone num from string.

n = randomNum;
return n;//ie. 453-1234
}


Try to use the regular expressions:

Regex re = new Regex(@"\([0-9]{3}-[0-9]{4})/", RegexOptions.Mu ltiline);
MatchCollection m = re.Matches(s);
return m[n].Group[1].Value; // n = 0..count-1, where count is a total number
of phone numbers.

--
_______________ _______________
With best wishes, Arthur Nesterovsky
Visit, please, my home page:
http://www.nesterovsky-bros.com
Nov 18 '05 #2
private string GetPhoneNumber( ) {
s = "\231-3423/\453-1234/\231-3473/\231-3474/";
string[] num = String.Split(s, "/\");

return num[n];
}
"Aaron" <ku*****@yahoo. com> wrote in message
news:b4******** *************** ***@posting.goo gle.com...
I would like to randomly output phone numbers seperated by \ and / from a string. s = "\231-3423/\453-1234/\231-3473/\231-3474/"

//c sharp code
private string GetPhoneNum()
{

//randomly pick a phone num from string.

n = randomNum;
return n;//ie. 453-1234
}

Thanks

Nov 18 '05 #3

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

Similar topics

2
455
by: Aaron | last post by:
I would like to randomly output phone numbers seperated by \ and / from a string. s = "\231-3423/\453-1234/\231-3473/\231-3474/" //c sharp code private string GetPhoneNum() { s = "\231-3423/\453-1234/\231-3473/\231-3474/" //randomly pick a phone num from string. n = randomNum;
4
2267
by: Dim | last post by:
I found that C# has some buggy ways to process string across methods. I have a class with on global string var and a method where i add / remove from this string Consider it a buffer... with some values and separators class { private string globalvar = ""; private void manipulate (whattodo ) //substring, join, etc....
4
2311
by: Aaron | last post by:
I like like to randomly output phone numbers seperated by \ and / from a string s = "\231-3423/\453-1234/\231-3473/\231-3474/" private string GetPhoneNum() { s = "\231-3423/\453-1234/\231-3473/\231-3474/" //randomly pick a phone num from string. n = randomNum;
32
14801
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) ||
29
4299
by: zoro | last post by:
Hi, I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party string handling library that includes some very useful string functions, in particular I'm interested in BEFORE (return substring before a pattern), AFTER (return substring after a pattern), and BETWEEN (return substring between 2 patterns). My questions are: 1. Can...
4
3478
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...
9
4688
by: Let_Me_Be | last post by:
Hi all, I'm developing a small defensive programming toolkit for my own projects. So, here are my questions. 1) Is it possible to move from something like this: SAFECALL(foo();) to __safecall foo(); 2) I need to auto-add code to every method of particular class safeclass MyClass {
4
1971
by: MC felon | last post by:
hello again.. i want to design a program which takes in a string and replaces all 's' characters with 'sh'. how do i do it? thanks a lot!
2
2165
by: Mike Cain | last post by:
Hi, The Repeater control seems like exactly what I want to output rows of data from my database. However I need to do some manipulation to the data prior to it being output and I'm not understanding how to go about this properly. For instance, the db column "myVal" is defined as a double in the db. In my table I want to display the...
0
7915
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...
0
8205
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. ...
0
8339
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...
1
7967
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...
0
6619
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...
0
5392
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...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
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...

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.