473,836 Members | 1,381 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to split a string using ,fixed character length, variable text delimmiter

I'm working on a data file and can't find any common delimmiters in the
file to indicate the end of one row of data and the start of the next.
Rows are not on individual lines but run accross multiple lines.

It would appear though that every distinct set of data starts with a
'code' that is always the 25 characters long. The text is variable
however.

Assuming i've read the contents of the file into the string myfile, how
do i split my file into an array, using this variable text, fixed 25
character long, delimiter?

Thankyou!

Gary-

Dec 6 '06 #1
24 4868
Hello,
>Assuming i've read the contents of the file into the string myfile, how
do i split my file into an array, using this variable text, fixed 25
character long, delimiter?

You should probably be able to use Regex.Split(... ), with a good regular
expression of course. I can give you help on writing that regular
expression, but I'll have to know a lot more about the delimiter string.
Oliver Sturm
--
http://www.sturmnet.org/blog
Dec 6 '06 #2
How do *you* know it's a delimiter and not data?

In other words, if *I* were to look at the file, knowing nothing about it,
how could I tell what was a delimiter and what was data? How would you
explain to me what to look for?

When you can answer that, you can start thinking about how to pass that
information to a machine.

HTH
Peter

<ga********@myw ay.comwrote in message
news:11******** **************@ 16g2000cwy.goog legroups.com...
I'm working on a data file and can't find any common delimmiters in the
file to indicate the end of one row of data and the start of the next.
Rows are not on individual lines but run accross multiple lines.

It would appear though that every distinct set of data starts with a
'code' that is always the 25 characters long. The text is variable
however.

Assuming i've read the contents of the file into the string myfile, how
do i split my file into an array, using this variable text, fixed 25
character long, delimiter?

Thankyou!

Gary-

Dec 6 '06 #3
Thankyou for your replies. OK I have had another look at i think the
task has just got harder. The length isn't always 25 characters. But I
have found a pattern, hopefully this will help.
I am using this 'code' as a delimmiter because it always proceeds the
name of an item, and this file is essentially a database of items.
Following the name of an item, a number of item characteristcs specific
to that item are listed. Eventually the items characteristics are
completely listed and the next 'code' is encountered which proceeds the
next item in the database.

There does seem to be some identifiable traits of this code.
It appears to be always at least 20 characters long.

- The code is continuous there are no spaces present.
- It is always composed of letters ranging from A-Z, or numbers 0-9.
- The first two characters of this code are always letters raning from
A-Z.
- These two letters are repeated at least two other times during the
code.

e.g.

DODE86DODE86SZD O010144

So I guess what I am trying to do now is split the string, every time a
a string in encountered that is at least 20 characters long, is alpha
numeric, and has the first two letters repeated initself at least two
other times.

I think this is going to be tough?

Any ideas?

Thankyou-
Peter Bradley wrote:
How do *you* know it's a delimiter and not data?

In other words, if *I* were to look at the file, knowing nothing about it,
how could I tell what was a delimiter and what was data? How would you
explain to me what to look for?

When you can answer that, you can start thinking about how to pass that
information to a machine.

HTH
Peter

<ga********@myw ay.comwrote in message
news:11******** **************@ 16g2000cwy.goog legroups.com...
I'm working on a data file and can't find any common delimmiters in the
file to indicate the end of one row of data and the start of the next.
Rows are not on individual lines but run accross multiple lines.

It would appear though that every distinct set of data starts with a
'code' that is always the 25 characters long. The text is variable
however.

Assuming i've read the contents of the file into the string myfile, how
do i split my file into an array, using this variable text, fixed 25
character long, delimiter?

Thankyou!

Gary-
Dec 6 '06 #4
In case it wasn't obvious I would also like to add that the code has at
least one space at the start of it and the end of it.
ga********@mywa y.com wrote:
Thankyou for your replies. OK I have had another look at i think the
task has just got harder. The length isn't always 25 characters. But I
have found a pattern, hopefully this will help.
I am using this 'code' as a delimmiter because it always proceeds the
name of an item, and this file is essentially a database of items.
Following the name of an item, a number of item characteristcs specific
to that item are listed. Eventually the items characteristics are
completely listed and the next 'code' is encountered which proceeds the
next item in the database.

There does seem to be some identifiable traits of this code.
It appears to be always at least 20 characters long.

- The code is continuous there are no spaces present.
- It is always composed of letters ranging from A-Z, or numbers 0-9.
- The first two characters of this code are always letters raning from
A-Z.
- These two letters are repeated at least two other times during the
code.

e.g.

DODE86DODE86SZD O010144

So I guess what I am trying to do now is split the string, every time a
a string in encountered that is at least 20 characters long, is alpha
numeric, and has the first two letters repeated initself at least two
other times.

I think this is going to be tough?

Any ideas?

Thankyou-
Peter Bradley wrote:
How do *you* know it's a delimiter and not data?

In other words, if *I* were to look at the file, knowing nothing about it,
how could I tell what was a delimiter and what was data? How would you
explain to me what to look for?

When you can answer that, you can start thinking about how to pass that
information to a machine.

HTH
Peter

<ga********@myw ay.comwrote in message
news:11******** **************@ 16g2000cwy.goog legroups.com...
I'm working on a data file and can't find any common delimmiters in the
file to indicate the end of one row of data and the start of the next.
Rows are not on individual lines but run accross multiple lines.
>
It would appear though that every distinct set of data starts with a
'code' that is always the 25 characters long. The text is variable
however.
>
Assuming i've read the contents of the file into the string myfile, how
do i split my file into an array, using this variable text, fixed 25
character long, delimiter?
>
Thankyou!
>
Gary-
>
Dec 6 '06 #5
There does seem to be some identifiable traits of this code.
It appears to be always at least 20 characters long.

- The code is continuous there are no spaces present.
- It is always composed of letters ranging from A-Z, or numbers 0-9.
- The first two characters of this code are always letters raning from
A-Z.
- These two letters are repeated at least two other times during the
code.

e.g.

DODE86DODE86SZD O010144

So I guess what I am trying to do now is split the string, every time a
a string in encountered that is at least 20 characters long, is alpha
numeric, and has the first two letters repeated initself at least two
other times.
Who created this file? Are there no documentation which describes its
format? Can you post a sample of the data that shows at least 2
complete "records" or items? Is there anything in the file, perhaps a
header of some sort, that can shed any light on the format?

Chris

Dec 6 '06 #6
Hello,
>DODE86DODE86SZ DO010144

So I guess what I am trying to do now is split the string, every time a
a string in encountered that is at least 20 characters long, is alpha
numeric, and has the first two letters repeated initself at least two
other times.
Yes, well... you could try using a regular expression such as this:

[ ]([A-Z][A-Z])([A-Z0-9]+)(\1)([A-Z0-9]+)(\1)([A-Z0-9]+)[ ]

(This could also be simplified a bit.)
This does evaluate the double repetition of the initial two characters,
but it can't check the maximum length of the string at the same time. If
you'd just be searching the text in question for occurrences of the
expression, you could easily write an additional check in code, to find
out whether any given string has the correct maximum length. But if you're
using this expression in a Split() call, you couldn't do that...

Personally I would probably still use an expression such as this, to
search for that is, and do the splitting myself. If you can't do the
splitting fully automatically, you'll have to do it yourself in any case -
and using a regular expression to do the delimiter searching seems a
better option to me than coding up the search in C#.

Oliver Sturm
--
http://www.sturmnet.org/blog
Dec 6 '06 #7
I agree, that's' wonky sounding data :) How about something like this?
It's not quite what you want, but might give you a start. currently it
just finds the codes as you've described them and returns them, but
I've got to do some real work so...
I'm not great with Regular expressions so I've only used one to check
the first two characters occur three times. Oh and it's very scrappy.

private void fooTest2()
{
foreach(string s in
foo2(",,,12tt12 ttt12ttttttttt, ,ab111ab1111111 1111ab,"))
{
Console.WriteLi ne(s);
}
}
private System.Collecti ons.ArrayList foo2(string pFoo)
{
int i;
int j;
int o=0;
int p=0;
System.Text.Reg ularExpressions .Regex r;
bool running=true;
char[] c;
String s;
System.Collecti ons.ArrayList a = new ArrayList();
c=pFoo.ToCharAr ray();

for(i=0, j=0; i<c.Length ; i=j)
{
for(;j<c.Length ;j++)
{
if(IsAN(c[j]))
{
if(running)
{
p++;
}
else
{
running = true;
p=1;
o=j;
}
}
else
{
running = false;
}
if(20 == p)
{
r = new
System.Text.Reg ularExpressions .Regex(pFoo.Sub string(o,2));
s=pFoo.Substrin g(o,j-o+1);
if(3 == r.Matches(s).Co unt)
{
p=0;
running = false;
a.Add(s);
}
else
{
running=false;
}
}
}
}
return a;
}
private bool IsAN(char pC)
{
char c = pC.ToString().T oUpper().ToChar Array()[0];
if('A' <= c && 'Z' >= c)
{
return true;
}
if('0' <= pC && '9' >= pC)
{
return true;
}
return false;
}

Dec 6 '06 #8
Hi it's used in a custom written programme where I work which is dos
based.
The developers have long since dissapeared.

I'd really like to know how to achieve this in code if possible,

Thanks,

Gary-
There does seem to be some identifiable traits of this code.
It appears to be always at least 20 characters long.
>
- The code is continuous there are no spaces present.
- It is always composed of letters ranging from A-Z, or numbers 0-9.
- The first two characters of this code are always letters raning from
A-Z.
- These two letters are repeated at least two other times during the
code.
>
e.g.
>
DODE86DODE86SZD O010144
>
So I guess what I am trying to do now is split the string, every time a
a string in encountered that is at least 20 characters long, is alpha
numeric, and has the first two letters repeated initself at least two
other times.

Who created this file? Are there no documentation which describes its
format? Can you post a sample of the data that shows at least 2
complete "records" or items? Is there anything in the file, perhaps a
header of some sort, that can shed any light on the format?

Chris
Dec 6 '06 #9
This group is amazing. Thankyou both very much, i'm going to explore
them both now.

Oliver Sturm wrote:
Hello,
DODE86DODE86SZD O010144

So I guess what I am trying to do now is split the string, every time a
a string in encountered that is at least 20 characters long, is alpha
numeric, and has the first two letters repeated initself at least two
other times.

Yes, well... you could try using a regular expression such as this:

[ ]([A-Z][A-Z])([A-Z0-9]+)(\1)([A-Z0-9]+)(\1)([A-Z0-9]+)[ ]

(This could also be simplified a bit.)
This does evaluate the double repetition of the initial two characters,
but it can't check the maximum length of the string at the same time. If
you'd just be searching the text in question for occurrences of the
expression, you could easily write an additional check in code, to find
out whether any given string has the correct maximum length. But if you're
using this expression in a Split() call, you couldn't do that...

Personally I would probably still use an expression such as this, to
search for that is, and do the splitting myself. If you can't do the
splitting fully automatically, you'll have to do it yourself in any case -
and using a regular expression to do the delimiter searching seems a
better option to me than coding up the search in C#.

Oliver Sturm
--
http://www.sturmnet.org/blog
Dec 6 '06 #10

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

Similar topics

5
31187
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it will split myString up using the delimiter of 1 space so that
11
2041
by: Sandfordc | last post by:
I have tried several time to do this but have been unsucessful. I tried something like: myFunction(charater) str=frm.s1.value sb1=str.substring(0,charater) sb2=str.substring(charater,str.length)
19
78857
by: Paul | last post by:
hi, there, for example, char *mystr="##this is##a examp#le"; I want to replace all the "##" in mystr with "****". How can I do this? I checked all the string functions in C, but did not find one.
2
5005
by: AlanL | last post by:
I am calling a Fortran DLL that has a declaration like: character * 260 variablename. I do not have the Fortran code. A path to a file is passed to the DLL. C# does not have a fixed character length. I can use vba or vb6 with Dim variablename as String * 260 and it works. However, I can not get this to work in C#. The DLL returns a value denoting that the file is not found. I even concatenated spaces to the string to make sure it...
1
1472
by: blue | last post by:
I have a table that I want to have a set width and height. The table has a title and the text may be larger than the width of the table. If the text is too large to fit into the table, it either line breaks or stretches the width of the table depending on how large a word is. For example, "this is a really long title" would line break, and "this_is_a_really_long_word", would stretch the width of the title I need the tables to be an...
5
9145
by: Neil Robbins | last post by:
I have a text file that stores a number of records that I need to access in a vb.net application. Each of the fields that make up a record are of a fixed number of bytes. So for instance there is an address field of 240 bytes and there is an id field of 12 bytes. Where the data stored in a field does not fill the available number of bytes then spaces " " are inserted to fill the remaining bytes. There are no delimiters, just fields of a...
13
14283
by: Martin Herbert Dietze | last post by:
Hi, I need to calculate the physical length of text in a text input. The term "physical" means in this context, that I consider 7bit-Ascii as one-byte-per character. Other characters may be longer, e.g. cyrillic would be 2 bytes per character. Is there a safe and easy way to notice non-7bit-Ascii input? Cheers,
1
1607
by: Garima12 | last post by:
Hi, There is a string like: parcel = 1 AND id = 546 OR shape = 'point' I want to split this string with AND and OR I wrote split function like: var contentarr = qString2.split("AND"); it will split the string where the AND is but I want string to be broken:
0
10854
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...
0
10559
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10601
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,...
0
9388
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7794
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
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4460
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
4023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3116
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.