Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with String 4

Status
Not open for further replies.

cumap

IS-IT--Management
Jul 9, 2007
268
US
Hi all,

Working with existing database that every message includes date/time. I'm now trying to break up strings and print them into 2 separate lines which include:

line 1: date (and time (if any))
line 2: message

Code:
response.write "<table cellspacing='2' cellpadding='10' width='100%'>"
						strTxt = split(trim(solution),"||")
						For x=0 to ubound(strTxt)
							response.write "<tr><td style='border:1px solid #006699'>"
							'preStr = instr(strTxt(x),"M:")
							'postStr= instr(strTxt(x),":") + 1
							if instr(strTxt(x),"AM:")>0 or instr(strTxt(x),"PM:")>0 then
								if instr(strTxt(x),"AM:") then
									breakpoint = instr(strTxt(x),"AM:")
								else
									breakpoint = instr(strTxt(x),"PM:")
								end if
							else
								breakpoint = instr(strTxt(x),":")
							end if
							response.write Left(strTxt(x),breakpoint) & "<BR>"
							response.write Right(strTxt(x),breakpoint)
							response.write "</td></tr>"
						Next
						response.write "</table>"

output according to the code:

» 05/04/07:
4/07: wewcfrf3rt
» 05/04/07:
yguykguykftycftu
» 05/04/07:
07: ghcghcguyk
» 10/30/2007 11:54:06 A
/30/2007 11:54:06 AM: Testing

getting from here in db

&#187; 05/04/07: wewcfrf3rt||&#187; 05/04/07: uiguyguykguykftycftu||&#187; 05/04/07: ghcghcguyk
||&raquo; 10/30/2007 11:54:06 AM: Testing


Anyway, I'm trying to create cases for existing data with DATE alone and new saved data with full Timestamp into the message.

Thanks
 
I got it, thank you anyway!

Instead of using RIGHT, I should utilize MID for the post-string behind the breakpoint

here is my new code
Code:
response.write "<table cellspacing='2' cellpadding='10' width='100%'>"
strTxt = split(trim(solution),"||")
For x=0 to ubound(strTxt)
	response.write "<tr><td style='border:1px solid #006699'>"
	if instr(strTxt(x),"AM:")>0 or instr(strTxt(x),"PM:")>0 then
		if instr(strTxt(x),"AM:") then
			breakpoint = instr(strTxt(x),"AM:") + 2
		else
			breakpoint = instr(strTxt(x),"PM:")
		end if
		postStr = breakpoint + 2
	else
		breakpoint = instr(strTxt(x),":")
		postStr	= breakpoint + 1
	end if
	'response.write breakpoint & "<BR>"
	'response.write postStr
	response.write LEFT(strTxt(x),breakpoint) & "<BR>"
	response.write MID(strTxt(x),postStr)
	response.write "</td></tr>"
Next
response.write "</table>"

however, I feel like crap looking through all these lines which I strongly believe there is a much better way to accomplish it. Please help showing me a shorter and proper way to do this.

Thanks!
 
You might try some "regular expression" kung fu.
 
regular expression"... what do you mean?
 
The regular expressions engine is a powerful pattern matching tool that can save you having to write your own complicated text parsing code.

Assuming you can get the pattern code correct, the rest is easy.

The pattern code can be difficult... looking at what you posted above, my first guess at a good pattern for your timestamps is: [tt]
"[0-9]{2}/[0-9]{2}/([0-9]{2}){1,2} [0-9]{2}:[0-9]{2}:[0-9]{2}( [aApP][mM])"[/tt]

 
I afraid I don't know how to get the "regular expression" done for the situation of mine. After reading your suggestion (and have no idea what your example meant), I did some google and pretty much understand that the regular expression is used for search matched data function. I don't see what good is it going to be for me here? Could you elaborate your example a little more, maybe there I can understand you better.

Thank you.
 
Microsoft have a surprisingly good intro to regular expressions here:


There is a handy on-line regex tester here:


___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
John, I've always had issues with Regular Expressions, so those links actually will be very handy, particularly the second one. Thanks!

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
That online tester is cool and it showed me that the first guess pattern was wrong. Big surprise! Ha!

Anyway, this pattern will do you better: [tt]
[0-9]{2}/[0-9]{2}/([0-9]{2}){1,2}(()|( [0-9]{2}:[0-9]{2}:[0-9]{2}( [aApP][mM])))[/tt]
 
I just spotted this (sort of) regex generator - might be fun to play with!


___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top