Can we capitalize the first letters of words in a string to Uppercase and return the string without using slice(1) in javascript? If possible please help me find this out?  function titleCase(str) {   str=str.toLowerCase().split(" ");   for(var i=0;i&lt;str.length;i++){     str[i] = str[i].charAt(0).toUpperCase()+str[i].slice(1);   }   str=str.join(" ");   return str; } titleCase("sHoRt AnD sToUt");
17417
Is there a simple way to convert a string to Title Case? E.g. john smith becomes John Smith. I'm not looking for something complicated like , just (hopefully) some kind of one- or two-liner.
79350
A word that starts with a lower-case (lowercase?) letter can be capitalized, but what is the converse action?  Google has only one page in the top results that addresses this and the closest thing to a proposed answer is decapitalize, which trips spell-checkers, so de-capitalize.
93317
I'm learning how to write programs in C using the k&amp;r book (The C Programming Language) and I have a problem with one of the exercises. It's asking me to detect and remove a character in string s1, which matches any characters in the string s2.  So, say s1 = "A";  And s2 = "AABAACAADAAE"  I want it to return "BCDE"  I know I'm on the right path towards it, i just don't know how to design programs very well, could you give me any additional tips. I tried to read about the binary search tree algorithm, but felt it was a little too advanced for this mundane task.  Thanks everyone!  /* An alternate version of squeeze(s1, s2) that deletes each character in  * s1 that matches any character in the string s2  *  * Angie@odfx.org  */  #include &lt;stdio.h&gt; #include &lt;string.h&gt;  void squeeze(char s[], char t[]);  char string[] = "BAD"; char sstring[] = "ABC";  int main(void) {     squeeze(string, sstring);     return 0; }  void squeeze(char s[], char t[]) {     int i, j, d;      d = 0;     if(strstr(s, t) == NULL)         printf("%c", s[i]);     s[j] = '\0'; }
24985
I saw , but I didn't see a JavaScript specific example. Is there a simple string.Empty available in JavaScript, or is it just a case of checking for ""?
6461
I would like to create a String.replaceAll() method in JavaScript and I'm thinking that using a regex would be most terse way to do it.  However, I can't figure out how to pass a variable in to a regex.  I can do this already which will replace all the instances of "B" with "A".  "ABABAB".replace(/B/g, "A");   But I want to do something like this:  String.prototype.replaceAll = function(replaceThis, withThis) {     this.replace(/replaceThis/g, withThis); };   But obviously this will only replace the text "replaceThis"...so how do I pass this variable in to my regex string?
44751
It might be a stupid question, but I always wondered (and was afraid to ask :)) why tags are written in lowercase whereas sometimes it's confusing and not really correct?  For example, IMHO, JComboBox is a better name than . The same about  and Java.  Is there any specific reason why all tags are lower-cased? It might confuse some users, as I always correct people who write ArrayIndexOutOfBounds instead of ..
54515
I want to implement numbering scheme like Microsoft Word uses for numbering.  first one gets = A,next is  B, next is C, .... then AA, then AB,....and so on.  as shown below   A        B  C  .   .  AA  AB  AC  .  .  AAA  AAB  ....   '=>' here means converted to.  some examples:       1 =&gt; A 26 =&gt; Z 27 =&gt; AA 52 =&gt; AZ 53 =&gt; BA   and heres the code for it:     var convertToNumberingScheme = function(n){         var x = n-1,             r26 = x.toString(26),             baseCharCode = "A".charCodeAt(0);          var arr = r26.split(''),             len = arr.length;          var newArr =arr.map(function(val,i){             val = parseInt(val,26);              if( (i === 0) &amp;&amp; ( len &gt; 1)){                 val = val-1;             }              return String.fromCharCode(baseCharCode + val);         });         return newArr.join('');     }   It seems to work fine, but any ideas if there are some potential bugs or ways to  optimize this.
48986
I am quite newbie in LaTeX. Following examples in other questions for using lower case in titles, I tried to mimic them without success, when applying it to a section:  I am working in LyX2.0.  \documentclass{book}  \usepackage{textcase}  \begin{document} \chapter{X} \section{Y} \section{Introduction to A\MakeLowercase{g} compounds}  \end{document}   I get the error:  ! Undefined control sequence. \MakeLowercase ...owercaseUnsupportedInPdfStrings    l.17 ...roduction to A\MakeLowercase{g} compounds}   The control sequence at the end of the top line  of your error message was never \def'ed. If you have  misspelled it (e.g., `\hobx'), type `I' and the correct  spelling (e.g., `I\hbox'). Otherwise just continue,  and I'll forget about whatever was undefined.   Is this somehow possible to get?
37193
What is the preferred way to remove spaces from a string in C++? I could loop through all the characters and build a new string, but is there a better way?
77795
What words change meaning when the first letter is capitalised? The only word with this property that comes to mind is polish/Polish (the pronunciation also changes in this case, but that's not a necessity part of what I'm asking for).
40515
In C# is there a way to detect if a string is all caps?  Most of the strings will be short(ie under 100 characters)
17958
I'd like to use JavaScript to calculate the width of a string. Is this possible without having to use a monospace typeface?  If it's not built-in, my only idea is to create a table of widths for each character, but this is pretty unreasonable especially supporting  and different type sizes (and all browsers for that matter).
78901
I want to change the letter-case of a single character argument, and use that changed letter inside a \csname.  And I want to do it without an additional package.  For example, I want to pass a macro the letter {S}, and have it execute the macro \csname macros\endcsname, or pass it the letter {T}, and have it execute the macro \csname macrot\endcsname.    In my MWE, I show three approaches:   I didn't expect \lowercase to work, since I recall reading that it is not truly expanded until the last possible moment.  Surprisingly, it goes into an \edef okay, but it must not be truly expanded, because it breaks the \csname. I also formulated an approach where I used \numexpr to add 32 to the ASCII code of the argument and perform a \char upon that result.  Like \lowercase, it gives the appearance of being expandable, but it also fails inside the \csname. I finally achieve success with the stringstrings package.  Having written the package, I know the conversion was not pretty... essentially, it is an exhaustive 26-fold check of the form \if #1Aa\else\if #1Bb\else\if #1Cc\else...\fi\fi\fi, which has the virtue that it can be expandably placed into an \edef, and so it works.   There has to be a better way.  The MWE works only because I use the inefficiently calculated \tmp from METHOD 3 inside the \csname.  If I use \tmp from either of the two earlier methods, it breaks.  \documentclass{article} \usepackage{stringstrings} \def\macros{Expandably converted an S to a s} \def\macrot{Expandably converted a T to a t} \newcommand\convert[1]{%   %MAKE THE ARGUMENT LOWER CASE   1) LOWERCASE\\   \edef\tmp{\lowercase{#1}}% PRETENDS TO EXPAND, BUT FAILS IN \csname   Here is the ``expanded'' conversion: \tmp\\   % OR   2) ASCII CONVERSION\\   \edef\tmp{\expandafter\char\numexpr`#1+32\relax}% PRETENDS TO EXPAND, BUT FAILS IN \csname   Here is the ``expanded'' conversion: \tmp\\   % OR   3) STRINGSTRINGS PACKAGE\\   \caselower[q]{#1}\def\tmp{\thestring}% WORKS BUT USES A PACKAGE   Here is the ``expanded'' conversion: \tmp\\   %   Now use it in a csname: \csname macro\tmp\endcsname% } \begin{document} \convert{S}\par \convert{T} \end{document}       SUMMARY OF ANSWERS:  I have added egreg's code snippets into this MWE to produce a document (and not just terminal output), showing the methods put forth to this point:  \documentclass{article}  %%%%%%%%%%%%%%%%%%%%%%%%%%%% L3 APPROACH  \usepackage{expl3}  \ExplSyntaxOn \cs_set_eq:NN \Xexplower \tl_expandable_lowercase:n \ExplSyntaxOff  %%%%%%%%%%%%%%%%%%%%%%%%%%%% EGREG'S LESS HACKY SOLUTION  \def\explowerchar#1{%   \ifcase\numexpr`#1-`A\relax    a\or b\or c\or d\or e\or f\or g\or h\or i\or j\or k\or l\or m\or    n\or o\or p\or q\or r\or s\or t\or u\or v\or w\or x\or y\or z\else    #1\fi }  \def\explower#1{%   \doexplowerchar#1\relax }  \def\doexplowerchar#1{%   \ifx#1\relax   \else     \explowerchar{#1}\expandafter\doexplowerchar   \fi }  %%%%%%%%%%%%%%%%%%%%%%%%%%%% STEVE'S HACKY PACKAGE APPROACH  \usepackage{stringstrings}  %%%%%%%%%%%%%%%%%%%%%%%%%%%%  \def\macros{Expandably converted an S to a s} \def\macrot{Expandably converted a T to a t}  \begin{document}  \textbf{Steve's hacky approach}  \caselower[q]{S}\csname macro\thestring\endcsname\par \caselower[q]{T}\csname macro\thestring\endcsname  \textbf{egreg's less hacky approach}  \edef\lcstring{\explowerchar{S}}\csname macro\lcstring\endcsname\par \edef\lcstring{\explower{T}}\csname macro\lcstring\endcsname  \textbf{L3 approach}  \edef\lcstring{\Xexplower{S}}\csname macro\lcstring\endcsname\par \edef\lcstring{\Xexplower{T}}\csname macro\lcstring\endcsname  \end{document}
90842
As an example, this question is titled using sentence case. I've been going to lots of different meta sites (especially this one), and I think the needle bent on my oh-me-oh-my-my-ocd-oh-meter.  Can we please standardize on using either:   Sentence case Title Case AP Style Title Case   ... and then we can look at just converting titles automatically? This would be a switch, of course, but I'd only imagine turning it off on sites where program code or symbols might be present in titles. Or, it could just become part of editing guidelines.    Additionally, is this a horrible idea?   To see the differences between them, you can put any arbitrary title into  (we have no affiliation with them, it's just a tool I sometimes recommend to people).  We would also eventually adopt this for static routes, but I'm mostly talking about questions.
9861
How can I use Unicode-aware regular expressions in JavaScript?  For example, there should be something akin to \w that can match any code-point in Letters or Marks category (not just the ASCII ones), and hopefully have filters like [[P*]] for punctuation, etc.
82171
Every so often, I have to type some text consisting mostly of uppercase letters, but with an occasional lowercase letter—essentially, sentence case, but inverted. On Windows, I would simply have caps lock on the entire time, and pressing Shift would give me a lowercase letter. On OS X, however, if caps lock is on, I only get uppercase letters, whether Shift is pressed or not.  So, I can either hold down Shift the entire time I'm typing, letting go of it briefly to type a lowercase letter, or press Caps Lock twice for each lowercase letter I type. Neither works as well as what Windows does.  Is there a way to get Caps Lock to behave as it does on Windows, where pressing Shift while caps lock is on produces lowercase letters?  I am running 10.6.
859
For a poor man's implementation of near-collation-correct sorting on the client side I need a JavaScript function that does efficient single character replacement in a string. Here is what I mean (note that this applies to German text, other languages sort differently):  native sorting gets it wrong: a b c o u z ä ö ü collation-correct would be:   a ä b c o ö u ü z  Basically, I need all occurrences of &quot;ä&quot; of a given string replaced with &quot;a&quot; (and so on). This way the result of native sorting would be very close to what a user would expect (or what a database would return). Other languages have facilities to do just that: , in , , . But what about JavaScript? Here is what I have right now. // s would be a rather short string (something like  // 200 characters at max, most of the time much less) function makeSortString(s) {   var translate = {     &quot;ä&quot;: &quot;a&quot;, &quot;ö&quot;: &quot;o&quot;, &quot;ü&quot;: &quot;u&quot;,     &quot;Ä&quot;: &quot;A&quot;, &quot;Ö&quot;: &quot;O&quot;, &quot;Ü&quot;: &quot;U&quot;   // probably more to come   };   var translate_re = /[öäüÖÄÜ]/g;   return ( s.replace(translate_re, function(match) {      return translate[match];    }) ); }  For starters, I don't like the fact that the regex is rebuilt every time I call the function. I guess a closure can help in this regard, but I don't seem to get the hang of it for some reason. Can someone think of something more efficient?  Answers below fall in two categories:  String replacement functions of varying degrees of completeness and efficiency (what I was originally asking about) A  of  , which is now  among JS engines (not so much at the time of the question) and could solve this category of problem much more elegantly.