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

split a string by number

ad
I want to split a string into string[] by every a number.
for example
ss="abcdefghi;
split(ss,3) --> "abc", "def","ghi"

Are there this string function?

Nov 17 '05 #1
4 2520
ad <fl****@wfes.tcc.edu.tw> wrote:
I want to split a string into string[] by every a number.
for example
ss="abcdefghi;
split(ss,3) --> "abc", "def","ghi"

Are there this string function?


No. I suspect you could use a regex, but it would be easiest just to
write your own method to do this, using Substring repeatedly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
ad <fl****@wfes.tcc.edu.tw> wrote:
I want to split a string into string[] by every a number.
for example
ss="abcdefghi;
split(ss,3) --> "abc", "def","ghi"

Are there this string function?


No. I suspect you could use a regex, but it would be easiest just to
write your own method to do this, using Substring repeatedly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3
Hello

I guess there is no. But you can try this one:

string str = "abcdefghijklm";
int len = str.Length;
string[] strs = null;

if (len != 0)
{
// string array
strs = new string[(len - 1) / 3 + 1];

int i = 0, j = 0;

while (i < len)
{
strs[j] = str.Substring(i, Math.Min(3, len - i));
i += 3;
j ++;
}
}

if (strs != null)
{
foreach (string s in strs)
{
System.Diagnostics.Debug.WriteLine(s);
}
}
--
With best regards,
Andrew

http://www.codeproject.com/script/pr...asp?id=1181072
"ad" <fl****@wfes.tcc.edu.tw> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I want to split a string into string[] by every a number.
for example
ss="abcdefghi;
split(ss,3) --> "abc", "def","ghi"

Are there this string function?

Nov 17 '05 #4
Hello

I guess there is no. But you can try this one:

string str = "abcdefghijklm";
int len = str.Length;
string[] strs = null;

if (len != 0)
{
// string array
strs = new string[(len - 1) / 3 + 1];

int i = 0, j = 0;

while (i < len)
{
strs[j] = str.Substring(i, Math.Min(3, len - i));
i += 3;
j ++;
}
}

if (strs != null)
{
foreach (string s in strs)
{
System.Diagnostics.Debug.WriteLine(s);
}
}
--
With best regards,
Andrew

http://www.codeproject.com/script/pr...asp?id=1181072
"ad" <fl****@wfes.tcc.edu.tw> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I want to split a string into string[] by every a number.
for example
ss="abcdefghi;
split(ss,3) --> "abc", "def","ghi"

Are there this string function?

Nov 17 '05 #5

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

Similar topics

3
by: Martin Lucas-Smith | last post by:
I am trying to take a string and split it into a filename and a number where the number is what follows the *last* instance of a comma in that string. Split and explode won't work because if the...
11
by: Carlos Ribeiro | last post by:
Hi all, While writing a small program to help other poster at c.l.py, I found a small inconsistency between the handling of keyword parameters of string.split() and the split() method of...
9
by: martin | last post by:
Hi, a very newbie question. How do I split the adress and number to 2 variables? ex. "Kingsroad 347" = variabel1 = "Kingsroad" variabel2 = "347" Ill guess i have to search the string from...
9
by: Java and Swing | last post by:
Say I have a string which contains numbers separated by a comma... such as "0,1,2,3,4,5"...I want to split the string at the commas and return an array containing, 0,1...5. Suggestions? I've...
3
by: Ben | last post by:
Hi I am creating a dynamic function to return a two dimensional array from a delimeted string. The delimited string is like: field1...field2...field3... field1...field2...field3......
7
by: lgbjr | last post by:
Hi All, I'm trying to split a string on every character. The string happens to be a representation of a hex number. So, my regex expression is (). Seems simple, but for some reason, I'm not...
4
by: Michele Petrazzo | last post by:
Hello ng, I don't understand why split (string split) doesn't work with the same method if I can't pass values or if I pass a whitespace value: >>> "".split() >>> "".split(" ") But into...
12
by: Pascal | last post by:
hello and soory for my english here is the query :"how to split a string in a random way" I try my first shot in vb 2005 express and would like to split a number in several pieces in a random way...
2
by: Transcend2030 | last post by:
Hi, I'm having problems with string.split() My problem is; I have a sentence which the user inputs, I then input a word and the number of times that word appears in the sentence is displayed. ...
4
by: Gilberto | last post by:
Hello, I have a couple of forms using the code to FIND AS YOU TYPE from Allen Browne (http://allenbrowne.com/AppFindAsUType.html). It worked PERFECTLY until yesterday when i splitted the db into...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.