Link to home
Start Free TrialLog in
Avatar of sjsharp80
sjsharp80

asked on

Removing a fixed number of characters from text string

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
ASKER CERTIFIED SOLUTION
Avatar of jaysolomon
jaysolomon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Zvonko
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>



Avatar of jaysolomon
jaysolomon

mine works in all browsers

:P
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>
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>
4_Test

jay, here your example get "est" :)

no it is not devic

XX_Test with substring 3 = Test

Do You know for sure XX is Num?
also you only show 1 num and the questioner show two X's

so XX
ach sorry, i understood that is number :)
>>>Bascially I want to strip the first 3 characters from this string.
Avatar of sjsharp80

ASKER

Thanks Jay your first suggestion works perfectly

Cheers
Glad to have helped and thanks for the A
jAy :)