如何获得字符串的一部分? [英] how can get a portion of string ?

查看:91
本文介绍了如何获得字符串的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一些类似@variable(ID),@ Variable(Name)等的字符串.

首先,我想检查是否有@variable,然后我将仅获得ID或Name

任务1:检查"@variable"是否可用

如果是,那么我要取括号中的部分.

有人可以帮我写这段代码吗?

Suppose I have some string like that @variable(ID), @Variable(Name)etc.

firstly I want to check if there is any @variable then I will get only ID or Name

Task 1: Check is "@variable" is available

if yes then I want take the portion which is inside in the parenthesis.

Can anyone help me to write this code ?

推荐答案

是@variable单词始终位于字符串的开头
试试这个

is the @variable word is always at the start of the string
try this

var stringHolder = "@variable(ID)";
        if (stringHolder.Substring(0, "@variable".Length) == "@variable")
        {
            var getCode = stringHolder.Replace("@variable(", "").Replace(")", "");   
        }



我测试了我之前的代码,但出现错误
我更新了代码并正常工作



I test my previous code,it gets error
I update my code and its work fine


已引用此链接:

http://stackoverflow.com/questions/12209325/how-to- use-split-function-in-stored-procedure [ ^ ]
Refered this link:

http://stackoverflow.com/questions/12209325/how-to-use-split-function-in-stored-procedure[^]


这篇关于如何获得字符串的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆