Solved

How to format string output?

Posted on 2000-04-06
8
357 Views
Last Modified: 2006-11-17
I need to generate a report (text on several columns) using ASP pages. Data are extracted from a database and of course they don't have always ther same length.  Using other langages like C or Perl, there is a way to define how many characters are available to display a string (C is printf %15s, indicate that the string has always 15 position to be displayed). Of course a font like Courier will be used.

Is there something equivalent using ASP/VBScript?

0
Comment
Question by:joel011197
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 11

Expert Comment

by:thunderchicken
ID: 2690067
i don't know if this is what your looking for, but you can get certain text from a string using the MID function

<%
dim thetext
thetext = MID(yourstring,<start position>,<total length>)
response.write(thetext)
%>

this would display the first 15 characters if you put

thetext = MID(yourstring,1,15)
0
 

Author Comment

by:joel011197
ID: 2690088
Ok with the Mid function, but if the string is not 15 character long but less (let's say 8), it will only use 8 positions and the display the follwoing information. I would expect to make a kind a tabulator using a format function.
0
 
LVL 10

Accepted Solution

by:
makerp earned 50 total points
ID: 2690107
define your colunm widths as variables

String(string,number) returns a string number long made of string

then

String(" ",(Col_width - Len(your_string)))

so each time you print a field do this

define each col width i.e.

col1_width = 30

obj.WriteLine(my_field&String(" ",(Col1_width - Len(my_field))))
 
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:makerp
ID: 2690123
Function Format(string,width)
    Format = string&String(" ",(width - Len(string)))
End Function

then simply wrap output in that

obj.writeLine(Format(my_field,col1_width))
0
 
LVL 10

Expert Comment

by:makerp
ID: 2690137
whops i got thje params wrong way round in the string function

String(width,string)

String((Col1_width - Len(my_field))," ")
0
 

Author Comment

by:joel011197
ID: 2690143
Ok with the Mid function, but if the string is not 15 character long but less (let's say 8), it will only use 8 positions and the display the follwoing information. I would expect to make a kind a tabulator using a format function.
0
 
LVL 4

Expert Comment

by:ruperts
ID: 2693340
So if it is an 8 character string do you want to follow it with a character like '*' ?

0
 

Author Comment

by:joel011197
ID: 2693386
I did not know the String function, so I can fill my string with the desired character and so execute a knid of format operation. Thanks for your suggestions.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
wordpress display sub menu only when click 12 90
Select record with the most recent date 14 71
MS SQL 2008 and stored prodcures and dates 5 34
Display field if column exists 7 56
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question