Solved

How to format string output?

Posted on 2000-04-06
8
358 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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