Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / IDE / February 2006

Tip: Looking for answers? Try searching our database.

Find specific text in a string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ksrajalakshmi@gmail.com - 11 Feb 2006 07:30 GMT
Hai ,

in a textbox am having text as
"(20/100)+pay1*pay2" .it's a formula. and stored in a particular
variable.
string strformula="(20/100)+pay1*pay2" ;

i've to substitute the value of  the variable 'pay1' & 'pay2' and
finding the value of that strformula.
can any onr tell me how to find 'pay1' and 'pay2' in the variable
strformula. it's urgent and reply immediately.
Thanks in advance.
pvdg42 - 11 Feb 2006 15:39 GMT
> Hai ,
>
[quoted text clipped - 8 lines]
> strformula. it's urgent and reply immediately.
> Thanks in advance.

As you spelled "string" with a lower case 's', I'll assume you're writing in
C++.
You need to research the member functions available in the C++ string class.
particularly the various overloads of the find() function and the replace()
function..
If my assumption above is incorrect, please tell us which language and class
library you are using.

Signature

Peter [MVP Visual Developer]
Jack of all trades, master of none.

Kadaitcha Man - 12 Feb 2006 01:47 GMT
pvdg42 <pvdg42@newsgroups.nospam>, the boozing skid-row bum and
double-jointed lick-spigot who likes wretched nad sack sucking with
cadavers, and whose partner is a pink pants with a puffy divit, wrote in
<#K8rRFyLGHA.676@TK2MSFTNGP10.phx.gbl>:  

>> Hai ,
>>
[quoted text clipped - 16 lines]
> If my assumption above is incorrect, please tell us which language
> and class library you are using.

lol

Signature

Cooking tonight: Beastly earwax balls and garlic extract garnished with
ravished English sparrow carbuncle and mole ulcer extract, served in a
chilled skillet brimming with chewy pieces of sea slug and eggplant in
noxious stinking slime, a side of bread and a keg of green turtle drool.

Kadaitcha Man - 12 Feb 2006 01:51 GMT
ksrajalakshmi@gmail.com, the perspiring chiseler and thick-skulled brown
rod who likes vulgar 69ers with caribous, and whose partner is a
flesh-peddler with a slushy bunny tuft, wrote in
<1139643024.132357.104660@g47g2000cwa.googlegroups.com>:  

> Hai ,
>
[quoted text clipped - 8 lines]
> strformula. it's urgent and reply immediately.
> Thanks in advance.

From the *HELP* *TEXT*...

     Visual Basic
' This example demonstrates the String.Contains() method
Imports System

Class Sample
  Public Shared Sub Main()
     Dim s1 As String = "The quick brown fox jumps over the lazy dog"
     Dim s2 As String = "fox"
     Dim b As Boolean
     b = s1.Contains(s2)
     Console.WriteLine("Is the string, s2, in the string, s1?: {0}", b)
  End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'Is the string, s2, in the string, s1?: True
'

     C#
// This example demonstrates the String.Contains() method
using System;

class Sample
{
   public static void Main()
   {
   string s1 = "The quick brown fox jumps over the lazy dog";
   string s2 = "fox";
   bool b;
   b = s1.Contains(s2);
   Console.WriteLine("Is the string, s2, in the string, s1?: {0}", b);
   

/*
This example produces the following results:

Is the string, s2, in the string, s1?: True
*/

     C++
// This example demonstrates the String.Contains() method
using namespace System;
int main()
{
  String^ s1 = "The quick brown fox jumps over the lazy dog";
  String^ s2 = "fox";
  bool b;
  b = s1->Contains( s2 );
  Console::WriteLine( "Is the string, s2, in the string, s1?: {0}", b );

/*
This example produces the following results:

Is the string, s2, in the string, s1?: True
*/

     Visual Basic
' Sample for String.IndexOf(Char, Int32)
Imports System

Class Sample
  Public Shared Sub Main()

     Dim br1 As String =
"0----+----1----+----2----+----3----+----4----+----5----+----6----+-"
     Dim br2 As String =
"0123456789012345678901234567890123456789012345678901234567890123456"
     Dim str As String = "Now is the time for all good men to come to the
aid of their party."
     Dim start As Integer
     Dim at As Integer

     Console.WriteLine()
     Console.WriteLine("All occurrences of 't' from position 0 to {0}.",
str.Length - 1)
     Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2,
str)
     Console.Write("The letter 't' occurs at position(s): ")

     at = 0
     start = 0
     While start < str.Length AndAlso at > - 1
        at = str.IndexOf("t"c, start)
        If at = - 1 Then
           Exit While
        End If
        Console.Write("{0} ", at)
        start = at + 1
     End While
     Console.WriteLine()
  End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'All occurrences of 't' from position 0 to 66.
'0----+----1----+----2----+----3----+----4----+----5----+----6----+-
'0123456789012345678901234567890123456789012345678901234567890123456
'Now is the time for all good men to come to the aid of their party.
'
'The letter 't' occurs at position(s): 7 11 33 41 44 55 64
'
'

     C#
// Sample for String.IndexOf(Char, Int32)
using System;

class Sample {
   public static void Main() {

   string br1 =
"0----+----1----+----2----+----3----+----4----+----5----+----6----+-";
   string br2 =
"0123456789012345678901234567890123456789012345678901234567890123456";
   string str = "Now is the time for all good men to come to the aid of
their party.";
   int start;
   int at;

   Console.WriteLine();
   Console.WriteLine("All occurrences of 't' from position 0 to {0}.",
str.Length-1);
   Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2,
str);
   Console.Write("The letter 't' occurs at position(s): ");

   at = 0;
   start = 0;
   while((start < str.Length) && (at > -1))
       {
       at = str.IndexOf('t', start);
       if (at == -1) break;
       Console.Write("{0} ", at);
       start = at+1;
       
   Console.WriteLine();
   

/*
This example produces the following results:

All occurrences of 't' from position 0 to 66.
0----+----1----+----2----+----3----+----4----+----5----+----6----+-
0123456789012345678901234567890123456789012345678901234567890123456
Now is the time for all good men to come to the aid of their party.

The letter 't' occurs at position(s): 7 11 33 41 44 55 64

*/

     C++
// Sample for String::IndexOf(Char, Int32)
using namespace System;
int main()
{
  String^ br1 =
"0----+----1----+----2----+----3----+----4----+----5----+----6----+-";
  String^ br2 =
"0123456789012345678901234567890123456789012345678901234567890123456";
  String^ str = "Now is the time for all good men to come to the aid of
their party.";
  int start;
  int at;
  Console::WriteLine();
  Console::WriteLine( "All occurrences of 't' from position 0 to {0}.",
str->Length - 1 );
  Console::WriteLine( "{1}{0}{2}{0}{3}{0}", Environment::NewLine, br1, br2,
str );
  Console::Write( "The letter 't' occurs at position(s): " );
  at = 0;
  start = 0;
  while ( (start < str->Length) && (at > -1) )
  {
     at = str->IndexOf( 't', start );
     if ( at == -1 )
           break;}

     Console::Write( "{0} ", at );
     start = at + 1;
 

  Console::WriteLine();
}

/*
This example produces the following results:

All occurrences of 't' from position 0 to 66.
0----+----1----+----2----+----3----+----4----+----5----+----6----+-
0123456789012345678901234567890123456789012345678901234567890123456
Now is the time for all good men to come to the aid of their party.

The letter 't' occurs at position(s): 7 11 33 41 44 55 64

*/

Signature

Cooking tonight: Dishonoured mule giblet and baboon nostril preserve
garnished with nearly raw live rat embryos and clove topping accompanied
by gone off carbuncle on top of packed-up koala droppings with clove
vinaigrette accentuated with underdone marten puddings and north
american porcupine eye conserve, served in a turbid tureen filled with
chewy bits of heart, veal and lamb in disgusting goo, a side of chipmunk
cervix and a pitcher of an unidentifiable organ juice.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.