Solved

Removing a fixed number of characters from text string

Posted on 2004-03-22
12
394 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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