开发者

Obtains character with string Substring()

开发者 https://www.devze.com 2023-02-28 15:37 出处:网络
I need obtains some character from the names of a images, the format of that names is: 141000000005.jpg, 141000150005.jpg, 141004600007.jpg...etc. I make the split() to separe the \".jpg\", now I ne

I need obtains some character from the names of a images, the format of that names is:

141000000005.jpg, 141000150005.jpg, 141004600007.jpg...etc. I make the split() to separe the ".jpg", now I need obtains the character from the position 3 to 10, for example:

141000000005 --> 00000000

141000150005 --> 00015000

141004600007 --> 00460000

The names images comes in a List<string>, so I in this moment I make this:

    char[] timeCodeArray 开发者_StackOverflow社区= timeCodeList[i].ToCharArray();
    string timeCodeArrayString = Convert.ToString(timeCodeArray[3].ToString() +  
        timeCodeArray[4].ToString() + timeCodeArray[5].ToString() + timeCodeArray[6].ToString() + 
        timeCodeArray[7].ToString() + timeCodeArray[8].ToString() + timeCodeArray[9].ToString() + 
        timeCodeArray[10].ToString());

How can I make this with substring??


String substr = "141000000005".Substring(3, 8);


var timeCodeArrayString = timeCodeList[i].Substring(3,8)


mystring.Substring(3,7) -> return a string which starts at character 3 and take 7 charcaters


Looks like you want myString.Substring(3,8)

Just for reference, though it's a lousy solution for this particular problem, if you concatenate lots of strings with '+', you get a string, so you don't need to call Convert.ToString on the result.

0

精彩评论

暂无评论...
验证码 换一张
取 消