473,326 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

CharPos

2
Hi There,

I m working on C#.net platform for sorting & merging the text data but i have one problem in that..

How to jump on Charracter position . In VB 6.0 there is a SEEK() function to jump on char pos..

Thanks & Regard's
Nilesh
Oct 17 '06 #1
1 2216
bharathreddy
111 100+
Dear Nilesh,

You can use SubString of the string variable to achive this.

Left, Right and Mid functions in C#

In VB we used Left, Right and Mid methods but it not included in C#. But then again, there is always a suitable replacement. The Substring method.

The Substring method retrieves a substring from a specified string. Below is an example where u can see how to use the substring method to create the Left, Right and Mid functions.

namespace LeftRightMid
{
///
/// Summary description for Class1.
///
class LeftRightMid
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{

//assign a value to our string
string myString = "This is a string";
//get 4 characters starting from the left
Console.WriteLine(Left(myString,4));
//get 6 characters starting from the right
Console.WriteLine(Right(myString,6));
//get 4 characters starting at index 5 of the string
Console.WriteLine(Mid(myString,5,4));
//get the characters from index 5 up to the end of the string
Console.WriteLine(Mid(myString,5));
//display the result to the screen
Console.ReadLine();
}

public static string Left(string param, int length)
{
//we start at 0 since we want to get the characters starting from the
//left and with the specified lenght and assign it to a variable
string result = param.Substring(0, length);
//return the result of the operation
return result;
}
public static string Right(string param, int length)
{
//start at the index based on the lenght of the sting minus
//the specified lenght and assign it a variable
string result = param.Substring(param.Length - length, length);
//return the result of the operation
return result;
}

public static string Mid(string param,int startIndex, int length)
{
//start at the specified index in the string ang get N number of
//characters depending on the lenght and assign it to a variable
string result = param.Substring(startIndex, length);
//return the result of the operation
return result;
}

public static string Mid(string param,int startIndex)
{
//start at the specified index and return all characters after it
//and assign it to a variable
string result = param.Substring(startIndex);
//return the result of the operation
return result;
}

}
}



Regs
Bharath Reddy
India
Oct 17 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: this one | last post by:
I have the following code <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript"...
5
by: cbs7 | last post by:
Hi all I'm a complete newbie to web development and Javascript especially. I've been creating a form for a webpage and have used a validation script gen_validatorv2.js which I downloaded from the...
8
by: .Net Sports | last post by:
I am checking for text input on a form validation in javascript that required at least one numeric character along with any number of alpha characters for a given input text box. The below is a var...
2
benchpolo
by: benchpolo | last post by:
I have a series of data rows where I need to capture the text inside the double quotes, but due to the different text length, I'm not quite sure how to do it. Data: "INSUFFICIENT INFORMATION"...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.