Toad World® Forums

Java script to convert Entity Name from lower case to camel case


I did reverse engineering on SQL SERVER 2014 DB and the naming conventions in that model are as below
Entity Name: data_source, data_reference etc.
I am trying to modify those names according to our naming conventions. I want to remove underscore and make the first letter of each word CAPS
I took one of the sample Java script given by toad and modify it. I was successfully able to remove underscore but when I am trying to make first letter to CAPS in every word it is only changing for the first word.
This is what I want data_source = Data Source
data_reference = Data Reference
I am using this in java script Entity.Name = Entity.Name.split(“_”).join(“ “);
Entity.Name = Entity.Name.charAt(0).toUppercase() + Entity.Name.substr(1).tolowercase();
This is what I am getting data_source = Data source
data_reference = Data reference
I am new to Toad Data modeler and also I have very minimal knowledge of java script. Please provide your valuable suggestions


Hello Dm.satya,

this is not really Data Modeler related problem, but rather more general jScript one. I’ve tried my best to solve this (I’m not jScript expert) to solve your issue, and here is my result (it could be done in more efficient way probably, but as I sad, I’ve tried my best):

  function SnakeCase2CamelCase(word)
var find = /(^\w)|(\_\w)/g; return word.replace(find, function($0){return $0.toUpperCase();}).split('_').join('');
function main(){ for(i=0; i<Model.Entities.Count; i++)
Model.Entities.GetObject(i).Name = SnakeCase2CamelCase(Model.Entities.GetObject(i).Name); Model.RefreshModel(); // only to propagate changes }

I hope it will help you.