Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Feature Requests
 PowerHome Messageboard : PowerHome Feature Requests
Subject Topic: PAD function Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
gg102
Senior Member
Senior Member


Joined: January 29 2013
Location: United States
Online Status: Offline
Posts: 245
Posted: March 02 2013 at 10:42 | IP Logged Quote gg102

I have run into a couple situations when working with a flat file where it would be nice to have a string function of PAD.

It would be something like:
PAD(string,L/R,fill_char,result_len)

usage:
PAD("hello","L","9",10) resulting in: "99999hello"
PAD("hello","R",".",10) resulting in: "hello....."

Back to Top View gg102's Profile Search for other posts by gg102
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: March 02 2013 at 13:14 | IP Logged Quote dhoward

gg102,

Take a look at the "fill" function and let me know if it will work for you. Your examples would be coded like this:

Code:

fill("9",5) + "hello"
"hello" + fill(".",5)


Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
gg102
Senior Member
Senior Member


Joined: January 29 2013
Location: United States
Online Status: Offline
Posts: 245
Posted: March 02 2013 at 18:00 | IP Logged Quote gg102

Thank you Dave for your input and quick response.

The "fill" function is not exactly the same.

Using "fill" you pad the string by an amount, not specify the length of the resultant string.
To do this, you have to know the source length of the string up front (at codetime not runtime).

For myself, I wrote a macro which uses the fill function.

basically, using the fill function:

if (error check) then exit
else
IF (RIGHT)
"string" + fill( "pad_char",(result_len - LEN("string") )
IF (LEFT)
fill( "pad_char",(result_len - LEN("string")) + "string"

This allows you to fill to a result_length, at runtime.

Yes, you can "get there from here" using "fill", but the PAD function does the work for ya.

Typically, the stringlen of data in a variable would not be known at codetime.

it's just easier to call:

PAD("string","R",".",LEN)

I use this in flat file use where I want to write a column of data:

date       time &nbs p;  description    value
---------------------------------------
01/20/2013 00:00   room one         &nb sp; 3
01/20/2013 00:00   light     &n bsp;        5
01/20/2013 00:00   fan     &nbs p;         11
01/20/2013 00:00   another function   6
01/20/2013 00:00   meter     &n bsp;       22
01/20/2013 00:00   front meter        3


the stringlength of the variable data would be unknown until runtime. So to write
this in columns would be difficult without a pad function.
PAD-R for the description and PAD-L for the value

Thus the file write detail loop would be:
ph_writefile("{LOG_FILE_NAME}",0,
     today() + "   " +
     PAD("{variable1}","R"," ",20) +
     PAD("{variable2}","L"," ", 3) +
     char(10) + char(13)
     )


Anyways, no action required, just a suggestion.

PH ROCKS!   [:P]
Back to Top View gg102's Profile Search for other posts by gg102
 
gg102
Senior Member
Senior Member


Joined: January 29 2013
Location: United States
Online Status: Offline
Posts: 245
Posted: March 02 2013 at 18:01 | IP Logged Quote gg102

Well, the WEB page didn't make the columns correct but you get the idea.......
Back to Top View gg102's Profile Search for other posts by gg102
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum