How can I use the ReverseString
function in Delphi2009?
private def reverseHelper(word: String): String = { var result = new StringBuilder(word) if (word.head.isUpper) { result.setCharAt(0, word.head.toLower) result.setCharAt(word.length - 1, word.last.toUpper) } result.reverse.result()}
val formatString = str .split("[.,!?: ]+") .map(result => str.replaceFirst(result, reverseHelper(result))) .foreach(println)
Example:
Input: What is a sentence?
Ouput: Tahw si a ecnetnes?
but i have Array[String]: Tahw is a sentence?, What si a sentence?, What is a sentence?, What is a ecnetnes?
How i can write this in right format?
I have homework assignment: to write a function that reverse a string, and then write a function that reverses words in a string, using the first function. So if the input is: "have a nice day", the output will be: "day nice a have".I cannot understand why my code isn't working - I keep getting segmentation fault.The first function (reverse) works just fine. The problem is with the second one.I really need your help...Thank you in advance.
#include <stdio.h>#include <string.h> #include <stdlib.h> void reverse(char *a){ int i, j, size; char tmp; size = strlen(a); j=size-1; for(i=0; i<size/2; i++) { tmp=a[i]; a[i]=a[j]; a[j]=tmp; j--; }}void reverseAll(char *a){ int size; reverse(a); size = strlen(a); char *new = (char*)malloc(size+1); char *token = strtok(a, " "); reverse(token); strcpy(new, token); printf("%s ", new); while(token != NULL) { reverse(token); token = strtok(NULL, " "); strcat(new, token); }}int main(){ char a[15]= "have a nice day"; reverseAll(a); printf("%s ", a); return 0;}
I'm constrained to not use anything from <string.h>
.
I want to reverse each word in the passed string.
This is what I have so far:
#include <stdio.h>char * reversepPrint( char *name ){ char *normal = name, *reverse = name; while ( *reverse ) ++reverse; if ( normal < reverse ) { for ( ; normal < --reverse; ++normal ) { char c = *normal; *normal = *reverse; *reverse = c; } } return name;}int main( void ) { char s[] = "Simon liebt Pizza!"; printf("%s", reversepPrint(s)); return 0;}
My code is reversing the whole string, but I want individual words to be reversed - so the result for this example would be "nomiS tbeil !azziP"
.
I want to reverse a string in C++ without using a loop or any other classes than std::string. Only the following methods should be used to reverse the string:x.at(); s.size()/s.length(); x.substr(pos,len);I think the usage of a recursion would be the solution to this problem, but I didn't figure it out how to do it right.
I tried this version, but it doesn't work.
string reverseWrapper(string str, int i, string stringToReturn) {if(i < 0) return stringToReturn;//cout << stringToReturn << '\n' << str.at(i) << '\n';stringToReturn.push_back(str.at(i));return reverseWrapper(str, int(str.size()) - 1, stringToReturn);}string reverseWithoutLoop(string str) { string stringToReturn; if(!(stringToReturn.length() == str.length())) { return reverseWrapper(str, int(str.size()) - 1, stringToReturn); } return stringToReturn;}
Can you help me solving this problem?
Дом - Карта на сайта - Уединение - Звена - Copyright © 2019 Cortex IT Ltd : Контакт : admin @ cortexit.co.uk
Please note that by viewing our site you agree to our use of cookies (see Уединение for details). You will only see this message once.