Solved

Removing a fixed number of characters from text string

Posted on 2004-03-22
12
393 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now