dbTalk Databases Forums  

Concatenating Strings

comp.databases.filemaker comp.databases.filemaker


Discuss Concatenating Strings in the comp.databases.filemaker forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Thiago Jorge
 
Posts: n/a

Default Concatenating Strings - 10-26-2005 , 01:31 PM






Does anyone know if there is a function or how to write one that
concatenates a letter to a string a specific number of times?

For instance, I have letter H in a variable called $letter
I want to create a string that contains H a certain number of times
that is stored in another variable called $repetition.

So, when $repetition is 5 my string should be HHHHH

I was trying to write a custom function that uses another custom
function called VariableInitialize and trying to Loop adding H to that
string, but VariableInitialize seems to work only with number and not
characters.

PS: VariableInitialize function was obtained free from
www.briandunning.com

Thanks


Reply With Quote
  #2  
Old   
Dan Fretwell
 
Posts: n/a

Default Re: Concatenating Strings - 10-26-2005 , 02:45 PM






Is that the sort of thing?

Sring(letter;repetitions) =

Case(
repetitions = 1; letter;
String(letter;repetitions - 1) & letter
)

Thiago Jorge wrote:
Quote:
Does anyone know if there is a function or how to write one that
concatenates a letter to a string a specific number of times?

For instance, I have letter H in a variable called $letter
I want to create a string that contains H a certain number of times
that is stored in another variable called $repetition.

So, when $repetition is 5 my string should be HHHHH

I was trying to write a custom function that uses another custom
function called VariableInitialize and trying to Loop adding H to that
string, but VariableInitialize seems to work only with number and not
characters.

PS: VariableInitialize function was obtained free from
www.briandunning.com

Thanks


Reply With Quote
  #3  
Old   
42
 
Posts: n/a

Default Re: Concatenating Strings - 10-26-2005 , 02:45 PM



In article <1130351516.112596.101770 (AT) z14g2000cwz (DOT) googlegroups.com>,
thijorge (AT) gmail (DOT) com says...
Quote:
Does anyone know if there is a function or how to write one that
concatenates a letter to a string a specific number of times?
With FM7D or FM8A you can define a recursive function:

repeat (n,s) =
case(
n<1,""
n=1,s,
n>1,s& repeat(n-1,s))


Call repeat with (4,"h")

And you'll get

"h"&repeat(3,"h")

which expands to

"h"&"h"&repeat(2,"h")
....
"h"&"h"&"h"&"h"
hhhh

it will also work on strings (repeat(2,"xyz") = xyzxyz

if you don't have 7D or 8A you'd have to make do with a looping script
to build your string.


Quote:
For instance, I have letter H in a variable called $letter
I want to create a string that contains H a certain number of times
that is stored in another variable called $repetition.

So, when $repetition is 5 my string should be HHHHH

I was trying to write a custom function that uses another custom
function called VariableInitialize and trying to Loop adding H to that
string, but VariableInitialize seems to work only with number and not
characters.

PS: VariableInitialize function was obtained free from
www.briandunning.com

Thanks



Reply With Quote
  #4  
Old   
Bill Marriott
 
Posts: n/a

Default Re: Concatenating Strings - 10-26-2005 , 10:59 PM



Quote:
if you don't have 7D or 8A you'd have to make do with a looping script
to build your string.
A very simple way to do it that works without Developer powers is:

Left(Substitute ( "{plenty of spaces}"; " "; letter);repetition)

[Replace {plenty of spaces} with space characterss corresponding to as many
repetitions as you think you'll ever need. And make it $letter, $repetition
if you're using variables.]

It's not as cool as a recursive function, but gets the job done.

Bill

"42" <nospam (AT) nospam (DOT) com> wrote

Quote:
In article <1130351516.112596.101770 (AT) z14g2000cwz (DOT) googlegroups.com>,
thijorge (AT) gmail (DOT) com says...
Does anyone know if there is a function or how to write one that
concatenates a letter to a string a specific number of times?

With FM7D or FM8A you can define a recursive function:

repeat (n,s) =
case(
n<1,""
n=1,s,
n>1,s& repeat(n-1,s))


Call repeat with (4,"h")

And you'll get

"h"&repeat(3,"h")

which expands to

"h"&"h"&repeat(2,"h")
...
"h"&"h"&"h"&"h"
hhhh

it will also work on strings (repeat(2,"xyz") = xyzxyz

if you don't have 7D or 8A you'd have to make do with a looping script
to build your string.


For instance, I have letter H in a variable called $letter
I want to create a string that contains H a certain number of times
that is stored in another variable called $repetition.

So, when $repetition is 5 my string should be HHHHH

I was trying to write a custom function that uses another custom
function called VariableInitialize and trying to Loop adding H to that
string, but VariableInitialize seems to work only with number and not
characters.

PS: VariableInitialize function was obtained free from
www.briandunning.com

Thanks





Reply With Quote
  #5  
Old   
42
 
Posts: n/a

Default Re: Concatenating Strings - 10-27-2005 , 01:13 AM



In article <BtadnThHpqAIzf3eRVn-3g (AT) comcast (DOT) com>, wjm (AT) wjm (DOT) org says...
Quote:
if you don't have 7D or 8A you'd have to make do with a looping script
to build your string.

A very simple way to do it that works without Developer powers is:

Left(Substitute ( "{plenty of spaces}"; " "; letter);repetition)
I was aware of the left, 'plenty of spaces' solution, but it hadn't
occured to me to use a substitute to handle the "but I want an arbitrary
letter not spaces" problem.

Nice solution.


Reply With Quote
Reply




Thread Tools
Display Modes

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

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.