练习题 去除字符串中的某个给定字符串

原文发布时间为:2009-03-09 —— 来源于本人的百度文章 [由搬家工具导入]

using System;//去除“askdaskaskdaskg”中的所有ask字符
namespace unname
{
   public class Class1
    {
       public static void Main()
       {
           //注释部分为另一种做法
           //string str="askdaskaskdaskg";
           //string[] result = str.Split(new char[] { 'a', 's', 'k' });
           //for (int i = 0; i < result.Length; i++)
           //    Console.Write(result[i]);

           string str = "askdaskaskdaskg";
           str = System.Text.RegularExpressions.Regex.Replace(str, @"[ask]", "");
           Console.WriteLine(str);
           Console.ReadLine();
       }

   }
}

时间: 2024-08-08 11:34:00

练习题 去除字符串中的某个给定字符串的相关文章

Implement strStr()——字符串中第一次出现给定字符串的位置

本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41452047 Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Update (2014-11-02): The signature of the func

PHP判断字符串中是否包含指定字符串,支持中文哦

RT,随手写的 1 /** 2 * 判断字符串中是否包含指定字符串 3 * @var source 源字符串 4 * @var target 要判断的是否包含的字符串 5 * @return bool 6 */ 7 function hasstring($source,$target){ 8 preg_match_all("/$target/sim", $source, $strResult, PREG_PATTERN_ORDER); 9 return !empty($strResul

输入一个字符串,输出该字符串中对称的子字符串的最大长度。

public class LongestSymmtricalLength2 { /* * Q75题目:输入一个字符串,输出该字符串中对称的子字符串的最大长度. * 比如输入字符串“google”,由于该字符串里最长的对称子字符串是“goog”,因此输出4. */ public static void main(String[] args) { String[] strs = { "a","google", "elgoog", "agol

C# GetValueList 获得字符串中开始和结束字符串中间得值列表

/// <summary> /// 获得字符串中开始和结束字符串中间得值列表 /// </summary> /// <param name="styleContent">样式内容</param> /// <returns></returns> private MatchCollection GetValueList(string str, string s, string e) { return Regex.Mat

从一个字符串中提取一个子字符串

编写一个函数,它从一个字符串中提取一个子字符串.函数原型如下: int substr(char dst[], char src[],int start, int len) {} 目标是:从 src 数组起始位置向后偏移 start个字符的位置开始,最多复制 len 个非NUL 字符到 dst数组.在复制完毕之后, dst 数组必须以 NUL字节结尾.函数的返回值是存储于 dst 数组中的字符串的长度. #include<stdio.h> #include<stdlib.h> #de

从第一个字符串中删除第二个字符串中出现过的所有字符

// 从第一个字符串中删除第二个字符串中出现过的所有字符 #include <stdio.h> char* remove_second_from_first( char *first, char *second ) { if( first == NULL || second == NULL ) { printf("first or/and second should not be NULL\n"); return NULL; } char flag[256]={0}; ch

用php的strpos() 函数判断字符串中是否包含某字符串的方法

PHP strpos() 函数 strpos() 函数返回字符串在另一个字符串中第一次出现的位置. 如果没有找到该字符串,则返回 false.语法 strpos(string,find,start) 参数 描述string 必需.规定被搜索的字符串.find 必需.规定要查找的字符.start 可选.规定开始搜索的位置. 注释:该函数对大小写敏感.如需进行对大小写不敏感的搜索,请使用 stripos()函数.编辑本段例子 <?php echo strpos(www.idc-gz.com,"

JS 从一个字符串中截取两个字符串之间的字符串

/************************************************* 函数说明:从一个字符串中截取 两个字符串之间的字符串 参数说明:src_str 原串, start_str_loc开始查找的字符串, start_str起始字符串 end_str结束字符串 dep :两个字符串之间的字符串 /************************************************/ function analysysRespParam(src_str,s

C++ 在字符串中插入子串+判断字符串是否由空格组成

// Example3.cpp : 定义控制台应用程序的入口点. #include "StdAfx.h" #include <string> #include <iostream> using namespace std; int main(void) { string str,str1,str2; int index; //判断截取的子串是否由blanks组成 str=" cjc is a master."; str1="cjc