|
-
Hi,
Can anybody tell me how to create an array of a string splitted by the "Enter" key.
I tried:
splitted = step5.message.split("\n" );
didn't work!
Thanks,
Raoul
[Edited by raoul on 08-03-2001 at 05:46 AM]
-
proud new daddy!
try:
splitted = step5.message.split(newline);
flash5 has a 'newline' variable built in that covers it!
cheers!
-
Hi LuxFX,
newline was the first thing I came up with but it didn't work neither.
I am kind of stuck here as I need to parse all seperate lines of a multiline input textbox into seperate strings.
In Flash 4 for I used something like:
ord(substring(step5:the_message, i, 1)) eq 13)
in a loop for each character but it isn't accurate!
Is anybody able to help me with this?
Raoul
-
Hey raoul!
I'm not sure if I have this right , so I made 3 different methods to generate the array ... if you're looking to display the 'splitted' array, I think that the combination of 1 and 2 or 1 and 3 will suit your needs.
1. 'splitted' is an array, with the elements split correctly in generator, but it displays in a normal comma-delineated array in one string.
2. 'splitted2' is a split of 'message' also, and displays with a newline for each line from 'message', but generator only returns a single element to the object.
3. 'splitted3' is pushed from the 'splitted' array, and displays with a new line, but it includes the commas preceding each element ... generator returns the elements' length correctly, however.
..edit..
4. I added a 4th option, and I've pasted it in to the code below, which displays a multi-line string by concatenating the 'splitted' array with a newline delineating the text. With this method, you preserve 'splitted' array for further manipulation, and either leave as is for a single multi-line field, or change 'splitted4' to _root["newText"+j] for the left operand (and remove the 'newline' from the right operand) of it's 'for' loop to display separate fields, thusly:
_root["newText"+j] = splitted[j];
Hope this helps. 
http://members.shaw.ca/flashmath101/splitMessage.swf
http://members.shaw.ca/flashmath101/splitMessage.fla
Code:
splitted = [];
splitted2 = [];
splitted3 = [];
splitted = step5.message.split("\r");
splitted2 = step5.message.split("\r\n");
for (var j=0;j<splitted.length;j++) {
splitted3.push(splitted[j]+newline);
}
if (!active) {
for (var j=0;j<splitted.length;j++) {
splitted4 += (splitted[j]+newline);
}
active = 1;
}
splittedLength = splitted.length;
splitted2Length = splitted2.length;
splitted3Length = splitted3.length;
splitted4Length = splitted4.length;
Generator results:
Variable _level0.splitted = [object #1] [
0:"line1",
1:"line2",
2:"line3",
3:"line4",
4:"line5",
5:"line6",
6:"line7",
7:"line8",
8:"line9",
9:"line10"
]
Variable _level0.splitted2 = [object #2] [
0:"line1\rline2\rline3\rline4\rline5\rline6\rline7\rline8\rline9\rline10"
]
Variable _level0.splitted3 = [object #3] [
0:"line1\n",
1:"line2\n",
2:"line3\n",
3:"line4\n",
4:"line5\n",
5:"line6\n",
6:"line7\n",
7:"line8\n",
8:"line9\n",
9:"line10\n"
]
Variable _level0.splitted4 = "line1\nline2\nline3\nline4\nline5\nline6\nline7\nline8\nline9\nline10\n"
Richard
[Edited by Dickee on 11-06-2001 at 02:51 AM]
-
Hey Richard, thanks for that, very helpful!
using "\r" for the split returns exactly what I need, that solved the problem.
Again, thanks for the info!
raoul
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
|
Click Here to Expand Forum to Full Width
|