5

I'm trying to remove the first 13 characters of a string with this code:

requestToken = requestToken.substring(13);

However, I'm getting "has no method substring" error with NodeJS, the code above that mostly recommended in the Javascript forums does not work with NodeJS?

1
  • Not the answer, but substring(0,13) won't remove the first 13 characters. Commented Apr 26, 2012 at 17:26

7 Answers 7

8

it seems like requestToken may not be a string.

Try

requestToken = '' + requestToken;

and then requestToken.substring(13);

Sign up to request clarification or add additional context in comments.

3 Comments

This is invalid syntax I believe.
Was referring to the requestToken = " + requestToken; bit. Think you're missing a "?
Oh, I see. Sorry for the confusion, it shows up as a double quote for me. =]
5

substring (and substr) are definitely functions on the string prototype in node; it sounds like you're not dealing with a string

$ node
> "asdf".substring(0,2)
'as'

Comments

2

Convert requestToken to a string first:

requestToken = (requestToken+"").slice(13);

Comments

1

requestToken must not be a string then. It's likely some sort of object, and the string you want is likely returned by a method on, or a property of, that object. Try console.log(requestToken) and see what that really is.

You also want .slice() for removing the front of a string.

And you will likely end up with something like:

myString = requestToken.someProperty.slice(13);

Comments

0

Coercing it to a string may not solve your problem. console.log(typeof(requestToken)) might give you a clue to what's wrong.

Comments

0

Try to check your object/variable:

console.log( JSON.stringify(yourObject) );

or it's type by

console.log( typeof yourVariable );

Comments

0
requestToken.toString().slice(13);

or

if(typeof requestToken!="string")
{
   requestToken.toString().slice(13);
}else
{
   requestToken.slice(13);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.