Problem in appending a string to a already filled string builder(at the beginning by using INSERT) and then converting that to string array(C#3.0)


Edwin Goei
HOME ยป Programming Languages

I have a string builder like


StringBuilder sb = new StringBuilder("Value1");
sb.AppendLine("Value2");

Now I have a string say


string str = "value 0";

I did


sb.Insert(0,str);

and then


string[] strArr = sb.ToString().Trim().Replace("
", string.Empty).Split('
');

The result I am getting as (Array size of 2 where I should get 3)


[0] value 0 Value1
[1] value2

But the desired output being


<

Related to : Problem in appending a string to a already filled string builder(at the beginning by using INSERT) and then converting that to string array(C#3.0)
Problem in appending a string to a already filled string builder(at the beginning by using INSERT) and then converting that to string array(C#3.0)
Programming Languages

I have a string builder like


StringBuilder sb = new StringBuilder("Value1");
sb.AppendLine("Value2");

Now I have a string say


string str = "value 0";

I did


sb.Insert(0,str);

and then


string[] strArr = sb.ToString().Trim().Replace("
", string.Empty).Split('
');

The result I am getting as (Array size of 2 where I should get 3)


[0] value 0 Value1
[1] value2

But the desired output being


<
Appending a string to a string array while validating the string. c++
15/12/2014 2:10 am Programming Languages

The problem I'm having is prompting the user to enter whatever item appears on the console window and I have to then check if that string is valid. If it's valid, I have to then append that string, display all the items that appear in the player's inventory and deduct the player's money accordingly.

The problem starts at the playerInput function.

#include <iostream>
#include <iomanip>
#include <cctype>
#include <string>
#include <algorithm>

using namespace std;

const int items = 5;
const string ShopInventory[items] = {"Helms", "Boots", "Swords",
"Axes", "Leather Armors"};
const int ItemPrices[items]= {10, 5, 20, 30, 50};

void PrintShop();
int PlayerInput(string [], int&);

int main()
{
   string PlayerInventory[items];
   int playerMoney = 100;
   char Response;

   cout << "		Welcome traveler to my lovely shop. 
";

   cout << "
Feel free to browse many of the wonderful items within";
   cout << " this store. " << endl;

   PrintShop();

   while(toupper(Response) != 'N')
   {
      cout << PlayerInput(PlayerInventory, playerMoney);

      cout << "
Is there anything else that you would like to buy? ";
      cout << "Enter n or N to quit.
Else enter y or Y to continue. ";
      cin >> Response;

      while(toupper(Response) != 'Y' && toupper(Response) !=
'N')
      {
         cerr << "
Sorry, wrong input. Please try again.  ";
         cin >> Response;
      }
   }

   return 0;
}

void PrintShop()
{
   cout << endl;

   cout << "     ***** Shop Inventory ***** " << endl
<< endl;

   cout << "Shop items " << "		Price Per Item. " <<
endl << endl;

   for(int i=0; i<items; i++)
   {
      cout << i+1 << ".) " << left << setw(22)
<< ShopInventory[i];
      cout << left << setw(3) << ItemPrices[i]
<< " Gold" << endl;
   }
}

int PlayerInput(string PlayerInventory[], int &playerMoney)
{
   string input;

   cout << "
Enter what you would like to buy. ";
   getline(cin, input);

   while(find(begin(ShopInventory), end(ShopInventory), input) ==
end(ShopInventory))
   {
      cout << "
The item that you enter isn't in my inventory. ";
      getline(cin, input);
   }

   return playerMoney;
}

Converting String Builder to Strings Array in VB.NET
Programming Languages

I have a RadComoboBox with check boxes and I want to loop through the check boxes with String Builder. After getting the values in that format: {1,2,3,4} I want to convert it to stringArray in that format (1,2,3,4)Can anyone please show me how I can do this?This is my code:Dim sbPeopleTypes As New StringBuilder()Dim colGroups As IList(Of RadComboBoxItem) = rcbFilterPersonType.CheckedItemsFor Each item As RadComboBoxItem In colGroups sbPeopleTypes.Append(item.Value + ",")Nextaspx
Insert string in beginning of another string
Programming Languages

How to insert a string enclosed with double quotes in the beginning of the StringBuilder and String?


Eg:


StringBuilder _sb = new StringBuilder("Sam");

I need to insert the string "Hello" to the beginning of "Sam" and O/p is "Hello Sam".


String _s = "Jam";

I need to insert the string "Hello" to the beginning of "Jam" and O/p is "Hello Jam".


How to achieve this?




HD Wallpapers
3D
3D Abstract
City
Celebrities
Indian Celebrities
Cars
Travel
Girls
Animals Birds
Movies
Sports
Black White
Nature
Planes
Anime
Food Drink
Dreamy Fantasy
Architecture
Games
Space
Holidays
Flowers
Love
Artistic
Baby
Beach
Bikes Motorcycles
Macro
Computers
Vector
Funny
Army
Textures
Brands
Misc
Music
Other
Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .