62,268
社区成员
发帖
与我相关
我的任务
分享
string ss = "ab,cd.ee ef";
Regex regex = new Regex("([a-zA-Z]+)([,. ]|$)");
Match match = regex.Match(ss);
StringBuilder result = new StringBuilder();
while (match.Success)
{
result.Insert(0, match.Result("$1"));
result.Insert(0, match.Result("$2"));
match = match.NextMatch();
}
Console.WriteLine(result.ToString());
#include <iostream.h>
#include <string.h>
void main()
{
char s[90]="zhycheng hello world!";
int v=strlen(s);
int half=v/2;
for(int i=0;i<half;i++)
{
char temp=*(s+i);
*(s+i)=*(s+v-i-1);
*(s+v-i-1)=temp;
}
cout<<s<<endl;
}
#include <iostream.h>
#include <string.h>
void main()
{
char s[90]="zhycheng hello world!";
int v=strlen(s);
int half=v/2;
for(int i=0;i<half;i++)
{
char temp=*(s+i);
*(s+i)=*(s+v-i-1);
*(s+v-i-1)=temp;
}
string str = "abcd as,ccd.dsa"; //output "dsa.ccd,as abcd"
Regex regexNotLetter = new Regex(@"[^a-z]");
Regex regexLetter = new Regex(@"[a-z]+");
Stack stack = new Stack();
Console.WriteLine("start :" + str);
var letterMatches = regexLetter.Matches(str);
var notLetterMatches = regexNotLetter.Matches(str);
for (int i = 0; i < letterMatches.Count; i++)
{
stack.Push(letterMatches[i]);
if (i < notLetterMatches.Count)
{
stack.Push(notLetterMatches[i]);
}
}
Console.Write("result : ");
while (stack.Count > 0)
Console.Write(stack.Pop());
Console.Read();
public static void main(String[] args) {
System.out.println(reverse("asd,fsdf.gfg gdg".toCharArray()));
System.out.println(reverse("9ujf093u4fj.,,mskldjf".toCharArray()));
System.out.println(reverse("j.,/m".toCharArray()));
}
public static char[] reverse(char[] source) {
int len = source.length, t = 0;
char[] target = new char[len];
for (int i = 0; i < len; i++) {
if (!isWord(source[i])) {
copy(source, target, t, i);
t = i + 1;
target[len - i - 1] = source[i];
}
}
copy(source, target, t, len);
return target;
}
public static boolean isWord(char c) {
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
return true;
else
return false;
}
public static void copy(char[] source, char[] target, int start, int end) {
if (start >= end) {
return;
}
int len = source.length - start - end;
for (int i = start; i < end; i++) {
target[i + len] = source[i];
}
}
static void Main(string[] args)
{
string str = "Hello, you are the $#@ god*&^of^ the&world!";
Regex reg = new Regex("^[A-Za-z]$");
List<string> result = new List<string>();
string word = string.Empty;
foreach (var c in str.ToArray())
{
if (reg.IsMatch(c.ToString()))
{
word += c;
}
else
{
result.Add(word);
result.Add(c.ToString());
word = string.Empty;
}
}
result.Add(word);
for (int i = result.Count - 1; i >= 0; i--)
{
Console.Write(result[i]);
}
Console.ReadKey();
}
static void Main(string[] args)
{
string str = "abcd as,ccd.dsa";
Console.WriteLine(CustomReverse(str));
Console.Read();
}
static string CustomReverse(string str)
{
string result = "", temp = "";
for (int i = 0; i < str.Length; i++)
{
//if (Char.IsLetter(str[i]))
if (str[i] != ' ' && str[i] != ',' && str[i] != '.')
{
temp += str[i];
}
else
{
result = str[i] + temp + result;
temp = "";
}
}
result = temp + result;
return result;
}