我从一个包含'和'的维度的数据库中提取一些信息来表示英尺和英寸.我的字符串中的那些字符会导致我以后出现问题,我需要替换所有单引号和双引号.我可以成功获取通过这样做摆脱一个或另一个:
this.Vals.replace(/\'/g, "") To get rid of single quotes
Run Code Online (Sandbox Code Playgroud)
要么
this.Vals.replace(/\"/g, "") To get rid of double quotes
Run Code Online (Sandbox Code Playgroud)
如何在同一个字符串中删除这两个.我试过这样做
this.Vals.replace(/\"'/g, "")
Run Code Online (Sandbox Code Playgroud)
和
this.Vals.replace(/\"\'/g, "")
Run Code Online (Sandbox Code Playgroud)
但后来都没有被取代.
网站用于三星Galaxy Tab与Gingerbread OS.到目前为止使用的浏览器是Stock浏览器以及Dolphin HD.当用户进出网络覆盖时,本地存储中的项目似乎随机消失.存储似乎也无法完全避免浏览器崩溃或设备重启.奇怪的部分是存储通常不会完全清除,只是大量的项目丢失.有人听说过这个问题还是有什么建议吗?
编辑:通过本地存储我的意思是,
localStorage["Key"] = value;
Run Code Online (Sandbox Code Playgroud)
使用以下方法重复:
localStorage.getItem("Key");
Run Code Online (Sandbox Code Playgroud)
在每种情况下,直接在添加到本地存储后,该站点都能够检索和使用该数据.但是,通常在漫游或浏览器/平板电脑崩溃之后的某个时间,数据不再存在.我发现的一切都说本地存储应该存在,所以我真的不知道从哪里开始.
我看过一千个帖子,有人问如何在javascript中检测互联网连接,总有一个人说使用navigator.onLine,另一个人说它不可靠,只告诉你连接是否可用,而不是你有联系.
底线,navigator.onLine告诉我,即使3G/4G和WiFi打开并且他们不在飞机模式或其他任何东西,由于覆盖率差,用户是否无法联系那里的服务器?只是你的平均死区.
我有一个TableLayout,我在OnCreate的代码中动态添加内容.一旦Activity创建,它就会专注于我动态创建的EditTexts之一并显示键盘.在用户专门按下其中一个EditTexts之前,我不希望键盘显示.我试过了:
InputMethodManager input = (InputMethodManager) GetSystemService(InputMethodService);
input.HideSoftInputFromWindow(CurrentFocus.WindowToken, 0);
Run Code Online (Sandbox Code Playgroud)
但键盘仍然显示,并且CurrentFocus返回null.因此,当我尝试将焦点专门指向另一个视图然后执行上述操作时:
InputMethodManager input = (InputMethodManager) GetSystemService(InputMethodService);
title.FindFocus();
input.HideSoftInputFromWindow(CurrentFocus.WindowToken, 0);
Run Code Online (Sandbox Code Playgroud)
CurrentFocus仍然为空,键盘仍然显示.title是一个TextView,我已经在代码中有一个实例.我可以不专注于TextView还是还有其他我想念的东西?
在单元测试方面,我是一个全新的,所以请原谅我,如果这完全是无知的话.但即使我为预期和实际提供完全相同的值,我也无法通过单元测试.当我设置断点并逐步执行时,我已经确认预期变量和实际变量都是包含两个项目的字符串数组,blah和blah.但每次说"Assert.AreEqual失败时,测试仍然失败.预期:System.String []实际:System.String []"
namespace TestProject1
{
public class Testing
{
public string[] PMDate(string lastPm)
{
if (string.IsNullOrEmpty(lastPm))
return new []{"blah", "blah"};
string[] results = lastPm.Split(new[] {" "}, StringSplitOptions.None);
if (results.Length < 2)
return new[] {"blah", "blah"};
return results;
}
}
[TestClass()]
public class UnitTest1
{
[TestMethod()]
public void PmDateTest()
{
Testing test = new Testing();
string[] expected = test.PMDate("01/01/1900");
string[] actual = test.PMDate("01/01/1900");
Assert.AreEqual(expected, actual);
}
}
Run Code Online (Sandbox Code Playgroud)
}
我找不到如何在单声道中执行此操作的示例.
有帮助吗?
编辑:添加代码
foreach (equip item in list)
{
tr = new TableRow(this);
sp = new Spinner(this);
sp.LayoutParameters = lp2;
sp.Adapter = adapter;
sp.ItemSelected += new EventHandler<ItemEventArgs>(spinner_ItemSelected());
sp.SetSelection(Convert.ToInt32(item.status));
tr.AddView(sp);
}
private void spinner_ItemSelected(object sender, ItemEventArgs e)
{
Spinner spinner = (Spinner)sender;
string toast = string.Format ("You selected {0}", spinner.GetItemAtPosition (e.Position));
Toast.MakeText (this, toast, ToastLength.Long).Show ();
}
Run Code Online (Sandbox Code Playgroud) 在现有解决方案中,我添加了一个新的测试项目.在我的Test Project .cs文件中,我有一个用[TestClass]属性修饰的类和一个用[TestMethod]属性修饰的方法.我已经验证在Configuration Manager中检查了构建复选框是否为测试项目(因为我的谷歌搜索已经显示其他人遇到此问题).我已将Test Project设置为解决方案的启动项目.当我尝试开始测试时,我得到"无法启动测试项目,因为项目不包含任何测试".我真的很擅长单元测试.我错过了什么?
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
Whole bunch of stuff
Assert.Inconclusive("Done");
}
}
Run Code Online (Sandbox Code Playgroud)
更新:所以我打开了VS的新实例,转到File => New => Project => Test Project.没有触摸或编辑任何东西.直接到cs文件,这里是它的全部内容:
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace TestProject2
{
public class Inspection
{
public bool SubmitInsp()
{
return true;
}
}
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
Inspection insp = new Inspection();
bool result = insp.SubmitInsp();
Assert.IsTrue(result);
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试启动它时,关于项目不包含任何测试的相同错误.在构建输出"无法加载文件或程序集'〜\ my documents\visual studio 2010\Projects\TestProject2\bin\Debug\TestProject2.dll'或其中一个依赖项中也发现了这一点.不支持操作.(例外情况来自HRESULT:0x80131515)"
我不知道单位测试比这简单得多.有没有搞错???
我觉得这是我做过一千次的事情,所以不确定为什么现在这么困难.我创建了一个方法,根据用户的UTC偏移量简单地返回用户的今天日期.但是它不是返回类似日期的字符串,而是返回这个垃圾
"?/??/????"
Run Code Online (Sandbox Code Playgroud)
这是代码.
public string getToday(Context context)
{
var settings = PreferenceManager.GetDefaultSharedPreferences(context);
var offset = settings.GetInt("offset", -5);
var now = DateTime.UtcNow.AddHours(offset);
return now.ToShortDateString();
}
Run Code Online (Sandbox Code Playgroud)
当我使用断点进入代码时,偏移现在看起来都是正确的.现在包含所有看似准确的有效日期部分.关于将现在转换为字符串的事情似乎非常错误.还尝试过:
return now.ToString("MM/dd/yyyy");
Run Code Online (Sandbox Code Playgroud)
结果相同.奇怪的部分是下面的代码在另一个活动工作没有问题
var offset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours;
var now = DateTime.UtcNow.AddHours(offset);
now.ToString("MM-dd-yyyy")
Run Code Online (Sandbox Code Playgroud) 我理解错误告诉我的是什么,但我不知道我可以使用它认为标题功能,我正在尝试与自定义标题结合.
inspection_title.axml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/inspectionTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:marqueeRepeatLimit="-1"/>
Run Code Online (Sandbox Code Playgroud)
LiftInspection.cs
[Activity(ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait)]
public class LiftInspection : ExpandableListActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
string callInfo = Intent.GetStringExtra("CallInfo");
RequestWindowFeature(WindowFeatures.CustomTitle);
SetContentView(Resource.Layout.LiftInspection);
Window.SetFeatureInt(WindowFeatures.CustomTitle, Resource.Layout.inspection_title);
TextView title = (TextView) FindViewById(Resource.Id.inspectionTitle);
title.Text = callInfo;
}
Run Code Online (Sandbox Code Playgroud)
清单中没有其他标题自定义或任何内容.什么可能与CustomTitle结合生成此异常?
我动态地将div元素附加到现有元素div.但紧接着,我需要将另一个追加div到div我刚刚创建的动态.但我似乎无法找到动态创建div以便附加到它.我想也许DOM还没有意识到这一点,div因为我刚刚做到了.我该怎么做呢?
var serialModel = "Test Test";
$("#existingDiv").append("<div id = '" + serialModel + "'></div>");
$("#" + serialModel).append("<div>content here</div>")
Run Code Online (Sandbox Code Playgroud)
最后一行没有做任何事情.第二行产生新的div,但后来发现它无法附加到它.
android ×4
javascript ×4
c# ×2
html5 ×2
unit-testing ×2
.net ×1
jquery ×1
mobile ×1
offline ×1
replace ×1