I'm moving a piece of our programming code from client side to server side because of performance issues (note: not all code is in the post, just the part i'm having trouble with)
the specific piece i'm having trouble with is a piece of alias rewriting. Can somebody help me translating this part.
//1. Force UperCamelCase: "Een lange financiele 443 naam" -> "Een Lange Financiele 443 Naam"
var strTempAlias = this.strName.replace(/\b[a-z]/g, function (match) { return match.toUpperCase() });
//2. Only allow a-zA-Z chars. "Een Lange Financiele 443 Naam" -> "EenLangeFinancieleNaam"
strTempAlias = strTempAlias.replace(/[^a-zA-Z]/g, '');
//3. Until max length 25: progressive remove small characters: "EenLangeFinaNaam"
var intShrinkSize = 10
while (strTempAlias.length > 25 && intShrinkSize > 3) {
var r = new RegExp("([A-Z]+[a-z]{0," + intShrinkSize + "})([a-z]+)", "g")
strTempAlias = strTempAlias.replace(r, function (match, $1, $2) { return $1 });
intShrinkSize -= 2;
}
I've been able to convert steps 1 and 2 to .net code, but i can't figure out how to convert step 3.
Below you can find the converted versions in vb.net and c# (for me it doesn't matter which version is answered i can program both)
VB.NET
'1. Force UperCamelCase: "Een lange financiele 443 naam" -> "Een Lange Financiele 443 Naam"
Dim strTempAlias As String = StrConv(strAlias, VbStrConv.ProperCase)
'2. Only allow a-zA-Z chars. "Een Lange Financiele 443 Naam" -> "EenLangeFinancieleNaam"
strTempAlias = Regex.Replace(strTempAlias, "[^A-Za-z0-9]+", "")
'3. Until max length 25: progressive remove small characters: "EenLangeFinaNaam"
Dim shrinksize = 10
While strTempAlias.Length > 25 AndAlso shrinksize > 3
'last piece of code to translate
End While
C#
//1. Force UperCamelCase: "Een lange financiele 443 naam" -> "Een Lange Financiele 443 Naam"
string strTempAlias = Strings.StrConv(strAlias, VbStrConv.ProperCase);
//2. Only allow a-zA-Z chars. "Een Lange Financiele 443 Naam" -> "EenLangeFinancieleNaam"
strTempAlias = Regex.Replace(strTempAlias, "[^A-Za-z0-9]+", "");
//3. Until max length 25: progressive remove small characters: "EenLangeFinaNaam"
dynamic shrinksize = 10;
while (strTempAlias.Length > 25 && shrinksize > 3) {
//last piece of code to translate
}
}
I find the functionality of Array.prototype.join very useful because it only applies the join value to the "inner" connections of the elements in the array. Like so: ['Hey', 'there'].join('-') // Hey-...
I find the functionality of Array.prototype.join very useful because it only applies the join value to the "inner" connections of the elements in the array. Like so: ['Hey', 'there'].join('-') // Hey-...
I am using Bootstrap tabs to load a widget from a server. What I need is to load the tab content as soon as the user click the tab instead of the initial load of the page. For ex below is the HTML for ...
I am using Bootstrap tabs to load a widget from a server. What I need is to load the tab content as soon as the user click the tab instead of the initial load of the page. For ex below is the HTML for ...
Why I am getting the result of -'54'+30 expresion as -24 however when I tried to remove the (minus)- from expression then It is just concatenation of string and gives 5430 as output.Can anyone explain ...
Why I am getting the result of -'54'+30 expresion as -24 however when I tried to remove the (minus)- from expression then It is just concatenation of string and gives 5430 as output.Can anyone explain ...
i would like to know about, what does mean by module wrapper function and what does it do to my code ? (function (exports, require, module, __filename, __dirname) { });
i would like to know about, what does mean by module wrapper function and what does it do to my code ? (function (exports, require, module, __filename, __dirname) { });