Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Flex > Flex 2, 3 & 4

Reply
 
Thread Tools Rate Thread Display Modes
Old 02-03-2009, 04:47 AM   #1
dieyana
Registered User
 
Join Date: Feb 2009
Posts: 7
Unhappy how to split a string in log file

hiii...

could anyone help me.how i can split this string"i am new to this" using the white space delimiter.

and how should i declare this string before i can paste it in Flex?

thank u so much...
dieyana is offline   Reply With Quote
Old 02-03-2009, 04:51 AM   #2
fx.barrett
Paintball Freak
 
fx.barrett's Avatar
 
Join Date: Jul 2008
Location: Romania, TM
Posts: 467
Send a message via MSN to fx.barrett Send a message via Skype™ to fx.barrett
Default

Huh, my English is not that good Could you maybe give a concrete example? How should the output look like and what do you mean by "how should I declare this string before I can paste it in Flex" ? Paste what into Flex ? Why ? and what do you understand by "paste into Flex" because you can "load data into Flex" or "pass data to Flex" but not "paste data"...
__________________
FLASHFORUM.RO - You must speak Romanian in order to join.
BLOG.WISEBISOFT.COM - Share and Experiment.
fx.barrett is offline   Reply With Quote
Old 02-03-2009, 05:30 AM   #3
MontyCoder
Senior Member
 
Join Date: Nov 2006
Posts: 321
Default

ActionScript Code:
var myStr:String = "i am new to this"; var myArray:Array = myStr.split(" "); var myNewStr:String=myArray[0]+"-"+myArray[1]+"-"+myArray[2]; trace(myNewStr); //i-am-new
MontyCoder is offline   Reply With Quote
Old 02-04-2009, 01:44 AM   #4
dieyana
Registered User
 
Join Date: Feb 2009
Posts: 7
Question how to split a string into array

i'm sorry for the inconvenience...

ok,first: I got this line of codes in flex;
var queryStr:String = '127.0.0.1 - - [15/Sep/2008:10:37:14 -0700];
var params:Array = queryStr.split(" ");

i want to split them into array like this:127.0.0.1 [15/Sep/2008:10:37:14 -0700]
i know that i can use the "white space" as a delimiter in this case,but what i want to know is,where should i put the above codes?whether it should be in the <mx:script> or what??

second:do i have to declare an array before i can use this codes?

thank you so much in advance...
dieyana is offline   Reply With Quote
Old 02-04-2009, 05:13 AM   #5
MontyCoder
Senior Member
 
Join Date: Nov 2006
Posts: 321
Default

ok if this is ur string
var queryStr:String = '127.0.0.1 - - [15/Sep/2008:10:37:14 -0700]
than what u want on out output...?
MontyCoder is offline   Reply With Quote
Old 02-04-2009, 06:29 AM   #6
dieyana
Registered User
 
Join Date: Feb 2009
Posts: 7
Unhappy split a string

i want to output this string "127.0.0.1 - - [15/Sep/2008:10:37:14 -0700]" into two columns using the split function.can it be done?

thanks...
dieyana is offline   Reply With Quote
Old 02-04-2009, 08:49 AM   #7
fx.barrett
Paintball Freak
 
fx.barrett's Avatar
 
Join Date: Jul 2008
Location: Romania, TM
Posts: 467
Send a message via MSN to fx.barrett Send a message via Skype™ to fx.barrett
Default

Ever considered simply doing this ?

ActionScript Code:
var st:String = "127.0.0.1 - - [15/Sep/2008:10:37:14 -0700]"; var arr:Array = st.split(" - - "); trace("value1: " + arr[0] + "\n" + "value2: " + arr[1]);
__________________
FLASHFORUM.RO - You must speak Romanian in order to join.
BLOG.WISEBISOFT.COM - Share and Experiment.
fx.barrett is offline   Reply With Quote
Old 02-04-2009, 09:09 AM   #8
wvxvw
Holosuit User
 
wvxvw's Avatar
 
Join Date: Oct 2006
Location: Tel Aviv
Posts: 4,301
Send a message via ICQ to wvxvw
Default

Code:
<?xml version="1.0" encoding="utf-8"?>
<!-- SplitExample -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
	applicationComplete="applicationCompleteHandler()">
	<mx:Script>
		<![CDATA[
		private function applicationCompleteHandler():void
		{
			var stringToSplit:String = "127.0.0.1 - - [15/Sep/2008:10:37:14 -0700]";
			stringToSplit += " - - 127.0.0.1 - - [16/Sep/2008:10:37:14 -0700]";
			stringToSplit += " - - 127.0.0.1 - - [17/Sep/2008:10:37:14 -0700]";
			stringToSplit += " - - 127.0.0.1 - - [18/Sep/2008:10:37:14 -0700]";
			stringToSplit += " - - 127.0.0.1 - - [19/Sep/2008:10:37:14 -0700] - - ";
			var re:RegExp = /(?P<a>[^\2]+?)(\s\-\s\-\s)(?P<b>[^\2]+?)\2/g;
			var result:Array;
			do
			{
				result = re.exec(stringToSplit);
				if (result)
				{
					trace(result.a);
					trace(result.b);
					sourceArray.push({ a: result.a, b: result.b });
				}
				
			}
			while (result);
			dp.refresh();
		}
		]]>
	</mx:Script>
	<mx:DataGrid width="100%" height="100%">
		<mx:dataProvider>
			<mx:ArrayCollection id="dp">
				<mx:source>
					<mx:Array id="sourceArray"/>
				</mx:source>
			</mx:ArrayCollection>
		</mx:dataProvider>
		<mx:columns>
			<mx:DataGridColumn dataField="a"/>
			<mx:DataGridColumn dataField="b"/>
		</mx:columns>
	</mx:DataGrid>
</mx:Application>
But that would be much easier if you could pick up another delimiter.

EDIT: haha, oh, sorry, what was I thinking when I wrote that! Sure, just use Array.split(), what I've written is surely an overkill
__________________
The .NET open source editor for Flash and web developers
*This would be my contribution to the project*
couchsurfing if you need it

Last edited by wvxvw; 02-04-2009 at 09:17 AM.
wvxvw is offline   Reply With Quote
Old 02-04-2009, 09:38 AM   #9
fx.barrett
Paintball Freak
 
fx.barrett's Avatar
 
Join Date: Jul 2008
Location: Romania, TM
Posts: 467
Send a message via MSN to fx.barrett Send a message via Skype™ to fx.barrett
Default

^ Hahah, still, quite nice, nice. I always skipped classes where they were talking about RegExp... but still, RegExp si really great and although I'm not great at it I still use it from time to time.
__________________
FLASHFORUM.RO - You must speak Romanian in order to join.
BLOG.WISEBISOFT.COM - Share and Experiment.

Last edited by fx.barrett; 02-04-2009 at 09:44 AM.
fx.barrett is offline   Reply With Quote
Old 02-04-2009, 11:41 PM   #10
dieyana
Registered User
 
Join Date: Feb 2009
Posts: 7
Default thanks a lot

what you have done is really really great!!thanks a lot...it's really above my level..i'm just a beginner in exploring Flex.

u have solve my problem..just a little wonder when i use this code below;

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
var st:String = "127.0.0.1 - - [15/Sep/2008:10:37:14 -0700]";
var arr:Array = st.split(" - - ");

]]>
</mx:Script>
<mx:Label text="{arr}" id="myLabel"/>
</mx:WindowedApplication>

the output;

127.0.0.1,[15/Sep/2008:10:37:14 -0700]

why there is a "," there when i don't even define it in code??
dieyana is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mulitiple file names as a string in one XML attribute, then spliting into an array bkelson ActionScript 2.0 0 06-29-2007 08:42 PM
Calling EXE file and sending a string to it guy_logical Projectors and CDs 2 05-30-2005 10:02 AM
help with save to php padone Server-Side Scripting 6 05-21-2005 11:29 PM
test for string split into an array = done? Jessica lucidiastudios ActionScript 1.0 (and below) 10 05-07-2003 09:31 PM
a text file and a string 45degrees ActionScript 1.0 (and below) 11 10-18-2001 08:16 AM


All times are GMT. The time now is 04:23 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.