Angular JS中的对象数组中提取的字符串很少。值将显示为us-east-1
或uk-west-5
。
我想将每个字符串转换为US-East-1
或UK-West-5
等混合大小写。
我知道我可以通过splitting the strings by - and then to convert to toUpperCase() for the first item in array and then to convert only the first letter of the second item item in the array
达到同样的效果。
但还有其他可行的解决方案吗?
正则表达式怎么样?有人可以解释一下如何使用它吗?
答案 0 :(得分:1)
这应该有效。
搜索:
public class WebRole : RoleEntryPoint
{
public override bool OnStart()
{
// set preloadEnabled of each Site in this deployment to true
using (var serverManager = new ServerManager())
{
foreach (var mainSite in serverManager.Sites)
{
var mainApplication = mainSite.Applications["/"];
mainApplication["preloadEnabled"] = true;
}
serverManager.CommitChanges();
}
// call my warmup-code which will preload caches and do some other time consuming preparation
var localuri = new Uri(string.Format("https://{0}/api/warmup", RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"].IPEndpoint));
try
{
var request = (HttpWebRequest)WebRequest.Create(localuri);
request.Method = "GET";
var response = request.GetResponse();
}
catch { }
// send this thread to sleep in order to give the warmup-request a chance to complete BEFORE the Role will get started
// and becomes available to the outside world
System.Threading.Thread.Sleep(60000);
return base.OnStart();
}
}
替换为:
(\w+-)(\w)(\w+)
说明:
\U$1\U$2\L$3
输入:
\U => Uppercase
\L => Lowercase
输出:
us-east-1 or uk-west-5