超出范围异常 - 子串 - C#(Out of Range Exception - Substring - C#)
我有一些电话号码列表,其中一些有扩展名,有些则没有。 我正式使用我的电话号码只返回数字。
然后我为前10位数字(区号+数字)创建一个字符串。
我比较这个字符串长度并将其与原始字符串进行比较。 如果存在差异,我将余数用作扩展名。
在下面的代码中,我一直在超出范围异常。 我调试了它,它似乎没有超出范围。 有人看到我错过了吗?
var prePhone = emp.y.PhoneNumber; if (!string.IsNullOrEmpty(prePhone)) { string xPhone = Regex.Replace(prePhone, "[^0-9]", ""); string number = xPhone.Substring(0, 10); int extMath = xPhone.Length - number.Length; if (extMath >= 1) { int preExt = 9 + extMath; string ext = xPhone.Substring(10, preExt);//Out of range exception em.Phone = beautifyPhoneNumber(number, ext); } else { string ext = null; em.Phone = beautifyPhoneNumber(number, ext); } }
I have a list of phone numbers some with extensions, some with out. I regex my phone number to return just the digits.
I then create a string for the first 10 digits(area code + number).
I compare this strings length and compare it to the original. If there is a difference, I use the remainder as the extension.
In the code below, I keep getting an out of range exception. I've debugged it, and it does not appear to be out of range. Anyone see what I'm missing?
var prePhone = emp.y.PhoneNumber; if (!string.IsNullOrEmpty(prePhone)) { string xPhone = Regex.Replace(prePhone, "[^0-9]", ""); string number = xPhone.Substring(0, 10); int extMath = xPhone.Length - number.Length; if (extMath >= 1) { int preExt = 9 + extMath; string ext = xPhone.Substring(10, preExt);//Out of range exception em.Phone = beautifyPhoneNumber(number, ext); } else { string ext = null; em.Phone = beautifyPhoneNumber(number, ext); } }
原文:
最满意答案
关于“一个项目的召唤”
Intent intent = new Intent(getApplicationContext(), nom.nom.example.A.yourClass); startActivity(intent);
A.yourClass中A的主要活动。
关于“B项目获取A数据”
Regarding with the "Call of A project"
Intent intent = new Intent(getApplicationContext(), nom.nom.example.A.yourClass); startActivity(intent);
where in A.yourClass is A's Main Activity.
Regarding with the "Access of A's data by B's project"
try looking at SharePreference or ContentProvider
相关问答
更多-
嗯,我会尝试解释一下我的经历。 我不认为自己是这方面的专家,但我几天打破了我的头脑。 对于初学者,我有一个非常糟糕的时间试图了解示例和应用程序的工作流程。 我认为从一个简单的例子开始应该更好,但是很难将代码分成小块,而不知道你是否打破任何东西。 我会告诉你我有什么,我从这个例子中改变了什么,使其工作。 我有一个活动,我的所有购买都来自。 它被称为Pro。 首先,您应该使用您的公开Market开发人员密钥更新Security类中的base64EncodedPublicKey,否则您将看到一个很好的异常。 嗯, ...
-
得到它了 ` Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH); intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS,"vnd.android.cursor.item/*"); startActivity(intent);` 上述作品 got it ` Intent intent = new In ...
-
如何在Android应用程序的亚马逊商店的应用程序计费中实现(how to implement in app billing for amazon store in android app)[2023-09-29]
问题是: 因此,您正在寻找一种方法,可以使用Google Android平台在亚马逊商店的应用内购买。 你需要什么: 因此,您需要通过将API合并到项目中来实施IAP(In App Purchasing)的过程。 如何实现您的需求: 执行此操作的详细过程将通过亚马逊的图像进行解释- 在应用程序采购中实施 - Android 。 此亚马逊网站链接中还提到了实现此目的所需的示例代码。 所以你可以得到一个有用的想法。 另外,您可以在Android Amazon AppStore的 Stackoverflow 应用 ... -
不幸的是,在您的Android应用程序中无法执行这些操作,因为这些调用需要秘密API密钥。 您绝对不应该在您的Android应用程序中拥有Secret API密钥,否则攻击者可能会得到他的手,然后代表您创建指控,退款或转账。 你需要做的是首先创建一个卡片令牌(你做的),然后将它发送到你的服务器,在那里你将使用你的密钥创建费用或客户。 这不会在你的Android应用程序中发生。 您可以参考这个其他问题: 使用Android发送分条令牌的正确方式,以检查某些Android代码如何向您的服务器发送令牌。 在服务器 ...
-
如果您只是试图隐藏某种类型的功能,则可以使用非常简单的应用程序来掩盖应用程序,如显示幻灯片的应用程序。 然后,您可以在面具应用程序中听按键或手势,并启动所需的功能或应用程序。 你也可以使用一种服务来监听各种有趣的事情。 如果您运行了一个后台服务,它可以监听传入的短信,您可以通过发送自己的特定代码来启动应用程序。 服务还可以监听顶级活动未处理的按键。 有很多方法可以做到这一点,尽管简单的遮罩应用可能是最简单的。 If you're simply trying to hide some type of func ...
-
你可以在这个链接上找到橡皮擦功能的实现,创建新的画布,刷子功能和保存功能: 创建android绘图界面 它有非常好的教程,使用动作事件在Android上制作绘图应用程序。 You can find the implementation of eraser function, create new canvas, brush function and save function, on this link : create android drawing interface it's have very go ...
-
在android中的/ system / app目录中安装应用程序(installing application in /system/app directory in android)[2022-03-29]
如果手机没有植根,或者您没有将自己的自定义ROM闪存到设备,则无法解决此问题。 There is no way to this if the phone is not rooted, or you are not flashing your own custom rom to a device. -
你可以使用Content Provider来做到这一点,你也可以使用Shared preferences做同样的事情 示例中使用共享首选项:用户登录一个应用程序时调用此方法。 public void writeSSOInfo(){ SharedPreferences prefs = getSharedPreferences("CheckSSO",Context.MODE_WORLD_READABLE); SharedPreferences.Editor ...
-
关于“一个项目的召唤” Intent intent = new Intent(getApplicationContext(), nom.nom.example.A.yourClass); startActivity(intent); A.yourClass中A的主要活动。 关于“B项目获取A数据” 尝试查看SharePreference或ContentProvider Regarding with the "Call of A project" Intent intent = new Intent(get ...
-
看看Nordic Id STIX uhf rfid阅读器。您可以使用USB端口将其连接到手机。 他们将为您提供应用程序开发的SDK。 链接: http : //www.nordicid.com/eng/products/? group = 7 Have a look at Nordic Id STIX uhf rfid reader.You can connect it to your phone using USB Ports. They will provide you SDK for Applicat ...