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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove Tildes and Text

Status
Not open for further replies.

jeffsal

Technical User
Oct 29, 2005
24
US
The following is a typical string in which I would like to remove any text between tildes and aslo remove all tildes.

BEFORE------------------------------------
Code[CRIM ] ~CIV~COLL~CORP~CRIM~EP~FAM~MISC~PI~PROB~RE~TAX~TINS~TRAF~WPOA~

TODO'S

Review File: 10 Days

Other[ ] ~20 Days~30 Days~

Close File: 60 Days

Other[ ] ~90 Days~120 Days~180 Days~
----------------------------------------------
AFTER

Code[CRIM ]
TODO'S

Review File: 10 Days

Other[ ]

Close File: 60 Days

Other[ ]
---------------------------------------------

Thanks for any help.














 
regexp to the rescue:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript">

var a = "Code[CRIM ] ~CIV~COLL~CORP~CRIM~EP~FAM~MISC~PI~PROB~RE~TAX~TINS~TRAF~WPOA~\n\nTODO'S\n\nReview File: 10 Days\n\nOther[ ] ~20 Days~30 Days~\n\nClose File: 60 Days\n\nOther[ ] ~90 Days~120 Days~180 Days~";
alert(a);
a = a.replace([!]/\~([A-Za-z0-9 ]+\~)+/[/!]g, "");
alert(a);

</script>

<style type="text/css">

</style>
</head>
<body>
</body>
</html>

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
or you could use the split function...

Code:
var a = "Code[CRIM ] ~CIV~COLL~CORP~CRIM~EP~FAM~MISC~PI~PROB~RE~TAX~TINS~TRAF~WPOA~\n\nTODO'S\n\nReview File: 10 Days\n\nOther[ ] ~20 Days~30 Days~\n\nClose File: 60 Days\n\nOther[ ] ~90 Days~120 Days~180 Days~";
alert( a.split("~")[0] );



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
The split function will still leave all the code that was between the tildes though, like CIV, COLL, CORP, etc...

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
That worked great. I got another one for ya. Any text NOT enclosed in brackets [] make bold. Thanks again.
 
kaht, have you tried it?

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]

<html>
<head>
<title>Untitled</title>
</head>

<body>

<script>
var a = "Code[CRIM ] ~CIV~COLL~CORP~CRIM~EP~FAM~MISC~PI~PROB~RE~TAX~TINS~TRAF~WPOA~\n\nTODO'S\n\nReview File: 10 Days\n\nOther[ ] ~20 Days~30 Days~\n\nClose File: 60 Days\n\nOther[ ] ~90 Days~120 Days~180 Days~";
alert( a.split("~")[0] );
</script>

</body>
</html>



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
the output from that is:
Code:
Code[CRIM ]

The OP wanted output of:
Code:
Code[CRIM ]
TODO'S

Review File: 10 Days

Other[ ]

Close File: 60 Days

Other[ ]
It would be difficult using the split function to determine what was between the tildes after it is split because every line like ~CIV~COLL~CORP~CRIM~EP~FAM~MISC~PI~PROB~RE~TAX~TINS~TRAF~WPOA~ would appear as multiple entries in the resulting array.

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
I got another one for ya. Any text NOT enclosed in brackets [] make bold. Thanks again.
 
That worked great. I got another one for ya. Any text NOT enclosed in brackets [] make bold. Thanks again.

jeffsal, have you attempted doing this yourself yet? I made up the original example because I like doing regexp, they can be challenging. However, Tektips is not intended to be a site to get your work done for you. We're here to help, not do your work for you. Your last post came as across like a "okay, that works - now do this one".

If you'd like to make a stab at it yourself and post the code that you're having problems with I'd be happy to tell you what to fix.

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Sorry. I didn't mean it to come off that way. I have only had a few times when I needed a little script and really have not had the time to learn it. Thanks again for the previous help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top