Solved

Removing a fixed number of characters from text string

Posted on 2004-03-22
12
395 Views
Last Modified: 2008-03-10
Hi,

I have the following text string on a page XX_Test, the program I am working with needs this format but when it is displayed in the browser I want it to just display Test, I want the format to be changed when the page loads.

Bascially I want to strip the first 3 characters from this string.

Thanks
0
Comment
Question by:sjsharp80
12 Comments
 
LVL 16

Accepted Solution

by:
jaysolomon earned 400 total points
ID: 10649347
<script type="text/javascript">
<!--
var str = "XX_Test";
document.write(str.substring(3));
// -->
</script>
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10649402
Check this:

<html>
<body onLoad="document.write(document.body.innerHTML.replace(/XX_/g,''))">
Hi,

I have the following text string on a page XX_Test, the program I am working with needs this format but when it is displayed in the browser I want it to just display Test, I want the format to be changed when the page loads.
Bascially I want to strip the first 3 characters from this string.

Thanks
</body>
</html>



0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10649414
mine works in all browsers

:P
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 25

Expert Comment

by:devic
ID: 10649418
Zvonko, i think must be this :)
===========
<html>
<body onLoad="document.write(document.body.innerHTML.replace(/[\d]{1,2}_/g,''))">
Hi,

I have the following text string on a page 66_Test, 21_Test, 4_Test,the program I am working with needs this format but when it is displayed in the browser I want it to just display Test, I want the format to be changed when the page loads.
Bascially I want to strip the first 3 characters from this string.

Thanks
</body>
</html>
0
 
LVL 8

Expert Comment

by:william_jwd
ID: 10649433
If you want to strip out anything before '_', then try this

<script type="text/javascript">
<!--
var str = "XX_Test";
document.write(str.substring(str.lastIndexOf('_') + 1));
// -->
</script>
0
 
LVL 25

Expert Comment

by:devic
ID: 10649448
4_Test

jay, here your example get "est" :)

0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10649457
no it is not devic

XX_Test with substring 3 = Test

Do You know for sure XX is Num?
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10649472
also you only show 1 num and the questioner show two X's

so XX
0
 
LVL 25

Expert Comment

by:devic
ID: 10649476
ach sorry, i understood that is number :)
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10649478
>>>Bascially I want to strip the first 3 characters from this string.
0
 

Author Comment

by:sjsharp80
ID: 10649958
Thanks Jay your first suggestion works perfectly

Cheers
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10650010
Glad to have helped and thanks for the A
jAy :)
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

809 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