Jump to content

VBScript trim newlines


justsomeguy

Recommended Posts

In ASP classic/VBScript, how the heck are you supposed to be able to trim newlines off the end of a string? Apparently the trim functions trim all whitespace except newlines. For example, in this data, I need all newlines preserved except for the several at the end (ignore the period):

What is the capital of Assyria?Answer: 5Study: AssyriaBeirutDamascusTripoliFranceI... I don't know that.

Link to comment
Share on other sites

Hmm. Something like this?

Do While Right(theString, 1) = (Chr(13) & Chr(10))	theString = Replace(theString, (Chr(13) & Chr(10)), "", Len(theString), 1)Loop

uggggh....VB

Link to comment
Share on other sites

uggggh....VB
Yeah, I know. This turned out to be the solution:
Do While Right(question_array(qc), 2) = VbCrLf  question_array(qc) = Left(question_array(qc), Len(question_array(qc))-2)Loop

Apparently the Replace function will discard everything to the left of the start parameter (in this case, everything). I mean, why would you want to keep the rest of the string anyway, right? So a side effect of Replace is that the string gets truncated if start > 0.

Link to comment
Share on other sites

Apparently the Replace function will discard everything to the left of the start parameter (in this case, everything). I mean, why would you want to keep the rest of the string anyway, right? So a side effect of Replace is that the string gets truncated if start > 0.
Brutal. It's no wonder I don't write VB. Sorry you're stuck with it on your project!
Link to comment
Share on other sites

Yeah. One day, when I have the time, I will rewrite the LMS using PHP, and the lord will grin, and the people will feast upon the lambs and sloths, and carp and anchovies, and orangutans and breakfast cereals, and fruit-bats...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...