Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 34775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:07:53+00:00 2026-05-10T14:07:53+00:00

Using this question as the base is there an alogrithm or coding example to

  • 0

Using this question as the base is there an alogrithm or coding example to change some text to Pascal or Camel casing.

For example:

mynameisfred 

becomes

Camel: myNameIsFred Pascal: MyNameIsFred 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T14:07:54+00:00Added an answer on May 10, 2026 at 2:07 pm

    I found a thread with a bunch of Perl guys arguing the toss on this question over at http://www.perlmonks.org/?node_id=336331.

    I hope this isn’t too much of a non-answer to the question, but I would say you have a bit of a problem in that it would be a very open-ended algorithm which could have a lot of ‘misses’ as well as hits. For example, say you inputted:-

    camelCase('hithisisatest'); 

    The output could be:-

    'hiThisIsATest' 

    Or:-

    'hitHisIsATest' 

    There’s no way the algorithm would know which to prefer. You could add some extra code to specify that you’d prefer more common words, but again misses would occur (Peter Norvig wrote a very small spelling corrector over at http://norvig.com/spell-correct.html which might help algorithm-wise, I wrote a C# implementation if C#’s your language).

    I’d agree with Mark and say you’d be better off having an algorithm that takes a delimited input, i.e. this_is_a_test and converts that. That’d be simple to implement, i.e. in pseudocode:-

    SetPhraseCase(phrase, CamelOrPascal):     if no delimiters      if camelCase       return lowerFirstLetter(phrase)      else       return capitaliseFirstLetter(phrase)     words = splitOnDelimiter(phrase)     if camelCase        ret = lowerFirstLetter(first word)       else       ret = capitaliseFirstLetter(first word)     for i in 2 to len(words): ret += capitaliseFirstLetter(words[i])     return ret  capitaliseFirstLetter(word):     if len(word) <= 1 return upper(word)     return upper(word[0]) + word[1..len(word)]  lowerFirstLetter(word):     if len(word) <= 1 return lower(word)     return lower(word[0]) + word[1..len(word)] 

    You could also replace my capitaliseFirstLetter() function with a proper case algorithm if you so wished.

    A C# implementation of the above described algorithm is as follows (complete console program with test harness):-

    using System;  class Program {   static void Main(string[] args) {      var caseAlgorithm = new CaseAlgorithm('_');      while (true) {       string input = Console.ReadLine();        if (string.IsNullOrEmpty(input)) return;        Console.WriteLine('Input '{0}' in camel case: '{1}', pascal case: '{2}'',         input,         caseAlgorithm.SetPhraseCase(input, CaseAlgorithm.CaseMode.CamelCase),         caseAlgorithm.SetPhraseCase(input, CaseAlgorithm.CaseMode.PascalCase));     }   } }  public class CaseAlgorithm {    public enum CaseMode { PascalCase, CamelCase }    private char delimiterChar;    public CaseAlgorithm(char inDelimiterChar) {     delimiterChar = inDelimiterChar;   }    public string SetPhraseCase(string phrase, CaseMode caseMode) {      // You might want to do some sanity checks here like making sure     // there's no invalid characters, etc.      if (string.IsNullOrEmpty(phrase)) return phrase;      // .Split() will simply return a string[] of size 1 if no delimiter present so     // no need to explicitly check this.     var words = phrase.Split(delimiterChar);      // Set first word accordingly.     string ret = setWordCase(words[0], caseMode);      // If there are other words, set them all to pascal case.     if (words.Length > 1) {       for (int i = 1; i < words.Length; ++i)         ret += setWordCase(words[i], CaseMode.PascalCase);     }      return ret;   }    private string setWordCase(string word, CaseMode caseMode) {     switch (caseMode) {       case CaseMode.CamelCase:         return lowerFirstLetter(word);       case CaseMode.PascalCase:         return capitaliseFirstLetter(word);       default:         throw new NotImplementedException(           string.Format('Case mode '{0}' is not recognised.', caseMode.ToString()));     }   }    private string lowerFirstLetter(string word) {     return char.ToLower(word[0]) + word.Substring(1);   }    private string capitaliseFirstLetter(string word) {     return char.ToUpper(word[0]) + word.Substring(1);   } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 67k
  • Answers 67k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Have you tried following the steps in this project: http://csharpbits.notaclue.net/2008/05/introduction-this-project-is-going-to.html… May 11, 2026 at 12:03 pm
  • added an answer If you've removed the property from the project, that doesn't… May 11, 2026 at 12:03 pm
  • added an answer First, add a field to your users table to store… May 11, 2026 at 12:03 pm

Related Questions

Using this question as the base is there an alogrithm or coding example to
I am using the code I posted as an answer to this question to
This question discusses encrypting data on the iPhone using the crypt() function. As an
As I stated in this question , I am using SDL for a small
ADDED: This question is now, I believe, subsumed by this one: Using GNU Screen
This question is about using getter methods of a singleton object in worker threads.
From this question , a neat answer about using COALESCE to simplify complex logic
In this question , I asked about using queue's and threads in C#. I
(NOTE: This question is not about escaping queries, it's about escaping results) I'm using
In relation to this question on Using OpenGL extensions , what's the purpose of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.