|
-
March 24th, 2002, 05:25 PM
#1
Senior Member - 1000+ Club
PERL, split and Outcoded's nightmare
This should be an easy question... at least that's what we thought.
Does anyone know a way to feed a string into an array such that every character is a separate item? (Kinda like a string tokeniser if you see what I mean).
Thanks in advance, this one's driving me nuts.
-
March 25th, 2002, 11:15 AM
#2
Senior Member - 1000+ Club
-
March 26th, 2002, 04:05 PM
#3
Registered User
I know how to do this in C++ but not in Perl. Sorry.
-
March 26th, 2002, 05:28 PM
#4
Registered User
youd have to make a search of your string caracter per caracter but at first glance(i'll look it up further) you'd need a variable for each caracter of your string, you'd need to now or predict how many caracters you have in your srting. Like an automatic variable creator depending on the amount of caracters your string has.. Could be long and messy getting each and every caracter after that process.
I'll check if there is a function or anything that would ease the process. I'll even ask my teacher.. lol
-
March 26th, 2002, 07:25 PM
#5
Senior Member - 1000+ Club
Thanks for that, I'm reading in an ASCII file so the file size should equal the number of characters right?
Deity. I do some C++, so maybe if you can do it in base concepts (as opposed to a straight string buffer like I would in Java), that could help me get a feel of what's going on.
I've emailed one of my lecturers, who's an expert in PERL, but I'm waiting on an answer.
Thanks for all the help folks, this one's still taxing me
-
March 27th, 2002, 11:53 AM
#6
Registered User
Disclaimer to all coding gurus: I am by no means a C/C++ expert. If I make any obvious mistakes or errors, please point them out...nicely.
Well, C++ has two different styles of strings. There is the newer string class and the old character array (c.string). What you are talking about sounds like a conversion from the new class to the old. The c strings would assign a seperate element in a character array to each character in the string, and then termintate it with a NULL character. For example:
[code] char myChar[255]; </pre><hr></blockquote> would declare a c string with 255 elements. C++ has a conversion function built in called c_str(), which changes a typical string into a character string.
I can imagine other, less clean ways of accomplishing the same thing. If you setup a character array, and pulled a single character substring out of the original string then incrementally stored that value into the character array. Again, terminate the character array with a NULL value.
Hope this helps.
A bored admin is a very dangerous person...
-
March 27th, 2002, 01:07 PM
#7
Senior Member - 1000+ Club
Thanks, that's got me thinking.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|
Bookmarks