Jump to content

upper case the first char in new line


Nati323
 Share

Recommended Posts

this is not the case, if you try to bold it like this:

str.replace(/(^.)/gm, "<b>$1</b>");

its works, anyway i try to solve this with function, i says maybe its work, so i did:

function toup($m) { return $m.toUpperCase(); }document.getElementById("demo").innerHTML = str.replace(/^(.)/gm, toup("$1"));

its dosent work, i dont know why, if i try to use the function like that:

toup("hello")

its returns HELLO, but with the reg match its dosent work.

i thought that maybe the match dosent transform to the function, but if you change the function to:

function toup($m) { return $m + "abc" }

you will see the match + abc, so the match did transform to the function,so i am at a loss.i dont understand where the problem is...

Link to comment
Share on other sites

If you give it a function you don't say what the parameters are, you just give it the function:

str.replace(/^(.)/gm, toup);
It passes the list of parameters automatically, there's a description about what it passes to the function here:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...