How Do We Trim A Part Of URL?
Feb 26, 2006
How do we trim out or remove a part of a URL or path?
eg. http://www.mywebsite/folder/somefile.htm ----I want to trim
http://www.mywebsite/folder/ so All I have left is the file name.
<script language="JavaScript">
var pathtotrim = location.href;
document.write (pathtotrim);
</script>
View 10 Replies
ADVERTISEMENT
Apr 23, 2007
Using Regular Expressions (JavaScript 1.2/JScript 4+) :
String.prototype.lTrim =
function()
{
return this.replace(/^s+/,'');
}
String.prototype.lTrim =
function()
{
return this.replace(/s+$/,'');
}
String.prototype.trim =
function()
{
return this.replace(/^s+|s+$/g,'');
}
or for all versions (trims characters ASCII<32 not true
"whitespace"):
function LTrim(str) {
for (var k=0; k<str.length && str.charAt(k)<=" " ; k++) ;
return str.substring(k,str.length);
}
function RTrim(str) {
for (var j=str.length-1; j>=0 && str.charAt(j)<=" " ; j--) ;
return str.substring(0,j+1);
}
function Trim(str) {
return LTrim(RTrim(str));
}
http://msdn.microsoft.com/library/d...363906a7353.asp
http://docs.sun.com/source/816-6408-10/regexp.htm
View 27 Replies
View Related
Nov 29, 2005
Does java script provides inbuilt trimming function, if not then what
is the solution.
View 2 Replies
View Related
May 31, 2009
Is there really no string trim function in JS?
Code:
function trim(s)
{
return rtrim(ltrim(s));
[code].....
View 3 Replies
View Related
Jul 23, 2005
for all your javascript trimming needs...
function trim(inputString) {
if (typeof inputString != "string") return inputString;
return inputString
//clear leading spaces and empty lines
.replace(/^(s|
|
)*((.|
|
)*?)(s|
|
)*$/g,"$2")
//take consecutive spaces down to one
.replace(/(s(?!(
|
))(?=s))+/g,"")
//take consecutive lines breaks down to one
.replace(/(
|
)+/g,"
")
//remove spacing at the beginning of a line
.replace(/(
|
)s/g,"$1")
//remove spacing at the end of a line
.replace(/s(
|
)/g,"$1");
}
View 3 Replies
View Related
Oct 2, 2009
I'm working with SageCRM. When SageCRM outputs the company address, I kid you not, it outputs the value and then a crap ton of HTML non-breaking spaces, a break tag and then repeat for the other address lines.My client added a button to the page via the customization function that links over to MapQuest. But, all those non-breaking spaces mess up the URL.I'm trying to fix it, but I'm having some trouble and thought I'd throw it out to you all.
Code:
// Ninja'd this from somewhere to trim whitespace.
function trim(stringToTrim) {
[code]....
View 1 Replies
View Related
May 8, 2009
I have the following script that converts line breaks from plain text into HTML formatted paragraphs. It takes plain text from one text area field and outputs the new formatted text into another text area field.
function convertText(){
var noBreaks = document.getElementById("oldText").value;
noBreaks = noBreaks.replace(/
[code]....
View 8 Replies
View Related
Aug 21, 2009
I have a form in my homepage which takes some values. In that, a text box takes multiple values seperated by spaces. I have allowed only alphanumeric characters in that with the following code.
[Code]...
View 5 Replies
View Related
Apr 7, 2011
This works fine in FireFox:
$("#listname").val().trim()
But in safari it errors: $("#listname").val().trim() while this does work, $("#listname").val()
Why is that?
View 2 Replies
View Related
Nov 18, 2010
I am trying to make a simple trim function but this doesnt works.
function tr(input){
var i;
var str;
for(i=0; i<input.length-1; i++){
if(text.charAt(i)==" "){
str+=""+text.charAt(i)
} return str
}}
View 4 Replies
View Related
Jun 29, 2011
My trim() function seems to halt JavaScript execution in Chrome.
Code:
function trim(s) {
s = s.replace(/(^s*)|(s*$)/gi,"");
s = s.replace(/[ ]{2,}/gi," ");
[code]...
It works in IE and firefox.. no it doesn't.
View 2 Replies
View Related
Dec 7, 2010
Is there a way of trimming the value before checking it so that a space for example would still be NULL "".
Code:
if(document.sendmail.emailsubject.value == '')
{
msg += "Subject cannot be left blank.
";
error = true;
}
View 3 Replies
View Related
Sep 29, 2005
Just wanted to share two handy RegEx expressions to strips leading and
trailing white-space from a string, and to replace all repeated spaces,
newlines and tabs with a single space.
* JavaScript example:
String.prototype.trim = function() {
// Strip leading and trailing white-space
return this.replace(/^s*|s*$/g, "");
}
String.prototype.normalize_space = function() {
// Replace repeated spaces, newlines and tabs with a single space
return this.replace(/^s*|s(?=s)|s*$/g, "");
}
" one two three
".trim(); // --> "one two three"
" one two three
".normalize_space(); // --> "one two three"
View 5 Replies
View Related
Aug 2, 2010
Picture a table where each cell row is 50px tall, with 3 to 5 columns of varying length. For example: thumbnail, name, description, price, options. The thumbnail will always be the same size, but for efficiency of space, nothing else is.
My question is one of overflow. With long descriptions, overflow:hidden will keep things clean. But the most aesthetic presentation would be todynamically truncate the description with ellipses (...) somewhere just before the text runs off the end of the cell (like the ubiquitous [More...] feature, but first filling the cell as much as possible).
This is a typographically desirable feature, and I can come pretty close with php
Attachments
Screen shot 2010-08-02 at 9.20.26 PM.png
Size : 96.98 KB
Download : 278
View 4 Replies
View Related
Jun 6, 2007
I was trying:
Code:
<script>
function testtrim(value) {
alert(value.trim());
}
testtrim("Alex ");
</script>
The javascript don't work, my firebugs says:[value.trim is not a function] how to simulate an trim function?
View 4 Replies
View Related
Feb 23, 2010
how to trim strings in Javascript with variable lengths? For example:
My Option 1 (+$10.00)
Short Option (+$5.00)
Really long Option
I only want to trim off the (+$10.00) on My Option 1 and the (+$5.00) on Short Option. No trim necessary on Really long Option. When I'm done I want to be left with:
My Option 1
Short Option
Really long Option
View 4 Replies
View Related
Jun 20, 2006
If there is a unlimit long textfield, the user can type free text. It means that the client can type
I like eating very much.
How can I using regular expression to trim the spaces to single space?
View 4 Replies
View Related
Dec 8, 2011
I use this script for my online price search facility:
// JavaScript Document
jQuery.noConflict();
jQuery(document).ready(function () {
[code]....
View 1 Replies
View Related
May 3, 2011
is there any way to trim the filed value before using jquery validate plugin [URL]../Plugins/Validation/Validator.
View 1 Replies
View Related
Apr 19, 2010
I need help with substring or trim function in javascript. Find below my code. Selection holds the value Select State, and length of the string is 14. I need to equate the Selection value to string "Select State" and execute alert message.
function selected_item() {
if (Selection=="Select State")
alert("Select the State");[code]....
I tried this:
var state=Selection.substring(0,11); and then string would be equated to state variable. But it is not working.
View 9 Replies
View Related
Jun 17, 2009
I have a little problem and I hope that I need to get the path of the URL except for the first slash "/". Now if I use window.location.pathname I get an output like this: /about/about/9081ae1b02/
That is almost right but I need to get rid of the first slash (marked in red) so I get: about/about/9081ae1b02/
View 1 Replies
View Related
Sep 8, 2011
I'm trying to figure out how to split a url variable... I tried these two ways, with an alert to see my result, but I'm not getting anything.
[Code]...
View 8 Replies
View Related
Aug 16, 2010
I've got an idea for simplifying my code and avoid a bunch of switch functions but don't know how, though I assume it's possible.
How do I write a function to change/insert only part of an img src?
View 4 Replies
View Related
Jul 23, 2005
How do you print part of an html page using the javascript print()
function? Is it possible to put the printable area inside a
<div></div> block and print it, or can you use a hidden style then
print it?
Is there a site on the www which has some information?
View 4 Replies
View Related
Feb 15, 2006
Is it possible to refresh only part of a page rather than reload the
entire thing?
I have dropdown box that's populated from a database using ASP that I
need refreshed but I don't want to reload the entire page.
View 6 Replies
View Related
Jul 20, 2005
is it possible to use the javascript:window.print() command to print only a
part of my window, lets say a table without navigation?
View 1 Replies
View Related