VBScript count new lines

vbscript

I'm looking for a function on how to count how many new lines there are in a particular string that is being returned from the DB.

I've seen functions to do this JavaScript and PHP but none for VBScript.

I want to first check if there are Carriage Returns in the string (and count them), then I want to do a replace on them to a <br/> tag.

I suppose I could do the replace on vbCrLf and if it doesn't find one then there will probably be no harm done. However, for debugging purposes right now I would really like to get the count so I know what it is doing (and if it is what I'm expecting).

Any ideas on how to do this in VBScript

Best Answer

You can try to split the string and see the UBound of the array:

'Split the stringfile into lines
arrLines = Split(strData,vbCrLf)

lineNb = UBound(arrLines)

code adapted from here

Related Topic