[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


How to format string output?

Posted on 2000-04-06
Medium Priority
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?

Question by:joel011197
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
LVL 11

Expert Comment

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>)

this would display the first 15 characters if you put

thetext = MID(yourstring,1,15)

Author Comment

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.
LVL 10

Accepted Solution

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

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


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))))
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 10

Expert Comment

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

then simply wrap output in that

LVL 10

Expert Comment

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


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

Author Comment

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.

Expert Comment

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


Author Comment

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.

Featured Post

Technology Partners: 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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

656 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