RE: [Flashcoders] Equivalent of setCharAt to change a character in a string

2009-07-15 Thread Paul Steven
Thanks Bob

Strange that there is not a simpler solution. Ah well, I guess I had just
hoped there was something equivalent to setCharAt

No worries anyway, I have decided to recode using an array.

Cheers

Paul

-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Robert
Leisle
Sent: 14 July 2009 19:43
To: 'Flash Coders List'
Subject: RE: [Flashcoders] Equivalent of setCharAt to change a character in
a string

Ah yes. I missed that part.
How about this moderately less simple one using Kenneth's suggestion?

function swapCharAt(s:String, index:Number, char:String ):String{
var ptrn:RegExp = new RegExp("(.{"+index+"}).(.*)");
return( (s).replace(ptrn, "$1"+char+"$2") );
}
trace( swapCharAt("Flash", 2, "e") );

hth,
Bob

-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Steven
Sent: Tuesday, July 14, 2009 10:32 AM
To: Flash Coders List
Subject: Re: [Flashcoders] Equivalent of setCharAt to change a character in
a string

Thanks Robert - yes I am able to replace patterns but just wondered If  
simple way to change a particular character in a string based on the  
character index?

Thanks
Paul

Sent from my iPhone

On 14 Jul 2009, at 18:10, "Robert Leisle"  wrote:

> Does this not work for you?
>
> // Change the first instance only
> var myPattern:RegExp = /sh/;
> // Change all instances
> //var myPattern:RegExp = /sh/g;
> var str:String = "She sells seashells by the seashore.";
> trace(str.replace(myPattern, "sch"));
> // She sells seaschells by the seashore.
>
> Hth,
> Bob
>
> -Original Message-
> From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders- 
> boun...@chattyfig.figleaf.com] On Behalf Of Paul Steven
> Sent: Tuesday, July 14, 2009 8:50 AM
> To: 'Flash Coders List'
> Subject: [Flashcoders] Equivalent of setCharAt to change a character  
> in a string
>
> Probably something really simple but can't for the life of me recall  
> the syntax to change a particular character of a string.
>
> For example if I have the word "Flash" and want to change the letter  
> "a" to an "e", I was hoping there was a function like setCharAt(2,  
> "e");
>
> Btw I am coding in AS3.
>
> Thanks
>
> paul
>
>
> ___
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
>
>
> ___
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Equivalent of setCharAt to change a character in a string

2009-07-14 Thread Robert Leisle
Ah yes. I missed that part.
How about this moderately less simple one using Kenneth's suggestion?

function swapCharAt(s:String, index:Number, char:String ):String{
var ptrn:RegExp = new RegExp("(.{"+index+"}).(.*)");
return( (s).replace(ptrn, "$1"+char+"$2") );
}
trace( swapCharAt("Flash", 2, "e") );

hth,
Bob

-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Steven
Sent: Tuesday, July 14, 2009 10:32 AM
To: Flash Coders List
Subject: Re: [Flashcoders] Equivalent of setCharAt to change a character in
a string

Thanks Robert - yes I am able to replace patterns but just wondered If  
simple way to change a particular character in a string based on the  
character index?

Thanks
Paul

Sent from my iPhone

On 14 Jul 2009, at 18:10, "Robert Leisle"  wrote:

> Does this not work for you?
>
> // Change the first instance only
> var myPattern:RegExp = /sh/;
> // Change all instances
> //var myPattern:RegExp = /sh/g;
> var str:String = "She sells seashells by the seashore.";
> trace(str.replace(myPattern, "sch"));
> // She sells seaschells by the seashore.
>
> Hth,
> Bob
>
> -Original Message-
> From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders- 
> boun...@chattyfig.figleaf.com] On Behalf Of Paul Steven
> Sent: Tuesday, July 14, 2009 8:50 AM
> To: 'Flash Coders List'
> Subject: [Flashcoders] Equivalent of setCharAt to change a character  
> in a string
>
> Probably something really simple but can't for the life of me recall  
> the syntax to change a particular character of a string.
>
> For example if I have the word "Flash" and want to change the letter  
> "a" to an "e", I was hoping there was a function like setCharAt(2,  
> "e");
>
> Btw I am coding in AS3.
>
> Thanks
>
> paul
>
>
> ___
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
>
>
> ___
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Equivalent of setCharAt to change a character in a string

2009-07-14 Thread Paul Steven
Thanks Robert - yes I am able to replace patterns but just wondered If  
simple way to change a particular character in a string based on the  
character index?


Thanks
Paul

Sent from my iPhone

On 14 Jul 2009, at 18:10, "Robert Leisle"  wrote:


Does this not work for you?

// Change the first instance only
var myPattern:RegExp = /sh/;
// Change all instances
//var myPattern:RegExp = /sh/g;
var str:String = "She sells seashells by the seashore.";
trace(str.replace(myPattern, "sch"));
// She sells seaschells by the seashore.

Hth,
Bob

-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders- 
boun...@chattyfig.figleaf.com] On Behalf Of Paul Steven

Sent: Tuesday, July 14, 2009 8:50 AM
To: 'Flash Coders List'
Subject: [Flashcoders] Equivalent of setCharAt to change a character  
in a string


Probably something really simple but can't for the life of me recall  
the syntax to change a particular character of a string.


For example if I have the word "Flash" and want to change the letter  
"a" to an "e", I was hoping there was a function like setCharAt(2,  
"e");


Btw I am coding in AS3.

Thanks

paul


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Equivalent of setCharAt to change a character in a string

2009-07-14 Thread Robert Leisle
Does this not work for you?

// Change the first instance only
var myPattern:RegExp = /sh/;
// Change all instances
//var myPattern:RegExp = /sh/g;
var str:String = "She sells seashells by the seashore.";
trace(str.replace(myPattern, "sch"));
// She sells seaschells by the seashore.

Hth,
Bob

-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com 
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Steven
Sent: Tuesday, July 14, 2009 8:50 AM
To: 'Flash Coders List'
Subject: [Flashcoders] Equivalent of setCharAt to change a character in a string

Probably something really simple but can't for the life of me recall the syntax 
to change a particular character of a string.

For example if I have the word "Flash" and want to change the letter "a" to an 
"e", I was hoping there was a function like setCharAt(2, "e");

Btw I am coding in AS3.

Thanks

paul


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Equivalent of setCharAt to change a character in a string

2009-07-14 Thread Kenneth Kawamoto

trace(("Flash").replace(/(.{2}).(.*)/, "$1e$2"));

// Flesh

Perhaps not the answer, I know ;)

Kenneth Kawamoto
http://www.materiaprima.co.uk/

Paul Steven wrote:

Probably something really simple but can't for the life of me recall the syntax 
to change a particular character of a string.

For example if I have the word "Flash" and want to change the letter "a" to an "e", I was 
hoping there was a function like setCharAt(2, "e");

Btw I am coding in AS3.

Thanks

paul

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders