Solved

Removing a fixed number of characters from text string

Posted on 2004-03-22
12
392 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

744 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

15 Experts available now in Live!

Get 1:1 Help Now