Chr$(40,5) = "(((((" possible? [Solved]

Post

Posted
Rating:
#1 (In Topic #607)
Avatar
Regular
Godzilla is in the usergroup ‘Regular’
Hello,

We have a command in Gambas "Space" that will produce X number of repetitions of a space.

Code (gambas)

  1. Print "<"; Space$(8); ">"

The result is

Code (gambas)

  1. <        >

In certain circumstances, this ability is very helpful.

Is there a command in Gambas which would work similarly for any ASCII character, repeating it X number of times?? Or perhaps in a future release, the Chr$() command can be modified to have an optional second argument for number of repetitions? There's certain circumstances where this ability would save a lot of typing.

For example:

Code (gambas)

  1. For Counter = 100 DownTo 2
  2. TheString = Replace$(TheString,Chr$(40,Counter),Null,gb.Binary)
  3. TheString = Replace$(TheString,Chr$(41,Counter),Null,gb.Binary)

Code (gambas)

  1. (((((((((((Hello!)))))
becomes

Code (gambas)

  1. (Hello!)

Thank you.
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
Maybe the PadLeft PadRight commands of String from gb.util ?

/comp/gb.util/string/padleft - Gambas Documentation

wiki" said


Static Function PadLeft ( String As String, Length As Integer [ , Pad As String ] ) As String


SINCE 3.15
Returns a new string that right-aligns the characters in the original string by padding them on the left with a specified string pattern, for a specified total length.

String is the string to pad.

Length is the final length in UTF-8 characters.

Pad is the string pattern used for padding. By default, a space is used.

Examples

Print String.PadLeft("Gambas", 10, ".")
 ….Gambas

Print String.PadLeft("Gambas", 16, "×->")
×->×->×->×Gambas


BruceS
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
Try this: -

Code (gambas)

  1. Print String(5, Chr(40))

The output is: -

(((((
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
Godzilla is in the usergroup ‘Regular’
Bruce and cogier, both very workable and useful solutions. Thank you for your replies!
Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’
Hehe you are welcome.

My answer i thought was just how I'd do it with my knowledge.

Cogier seemed to hit the nail right on the head with the exact solution though
 (i didn't know you could even do that with String() :lol: )

PadLeft PadRight have other uses though and are also good commands to know of :)


knowledge is power :)
Online now: No Back to the top
1 guest and 0 members have just viewed this.