473,799 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to omitt the last word...

2 New Member
hi guys.. i have a problem on how to omit the last word..like for example i have this words;

cafe\restaurant \hotel

i would only like to view on the textbox.text the words only cafe\restaurant , the \hotel should be omitted or deleted..i'm using vb.net and here's my code if u could fix it...

For Each arr As String In x.Split ( "\",3,StringSpl itOptions.Remov eEmptyEntries)
Me.txtdepartmen t.Text = arr
Next

the ouput of this code is still cafe\restaurant \hotel..help please
Oct 4 '07 #1
5 1770
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
hi guys.. i have a problem on how to omit the last word..like for example i have this words;

cafe\restaurant \hotel

i would only like to view on the textbox.text the words only cafe\restaurant , the \hotel should be omitted or deleted..i'm using vb.net and here's my code if u could fix it...

For Each arr As String In x.Split ( "\",3,StringSpl itOptions.Remov eEmptyEntries)
Me.txtdepartmen t.Text = arr
Next

the ouput of this code is still cafe\restaurant \hotel..help please
You will have to convert it explicitly to an array and then loop the array.
I think at the moment the foreach loop goes throug once.

Expand|Select|Wrap|Line Numbers
  1. string[] arr = x.Split("\");
  2. foreach string s in arr
  3. {
  4. this.txtdepartment.text += s + " ";
  5. }
cheers
Oct 4 '07 #2
Plater
7,872 Recognized Expert Expert
I would recomend a regular for loop, as this will give you control over keeping the last word.

Expand|Select|Wrap|Line Numbers
  1. string[] arr = x.Split("\");
  2. //use < Length-1 to ensure you ignore the last word
  3. for (int i=0; i<arr.Length-1;i++)
  4. {
  5.  string temp=arr[i];
  6.  //do whatever you want with temp
  7. }
  8.  
or in vb.net:

Expand|Select|Wrap|Line Numbers
  1. Dim arr As String() = x.Split("\".ToCharArray()) 
  2. 'use < Length-1 to ensure you ignore the last word 
  3. For i As Integer = 0 To (arr.Length - 1) - 1 
  4.     Dim temp As String = arr(i) 
  5.     'do whatever you want with temp 
  6. Next 
  7.  
Oct 4 '07 #3
neobagsjol
2 New Member
I would recomend a regular for loop, as this will give you control over keeping the last word.

Expand|Select|Wrap|Line Numbers
  1. string[] arr = x.Split("\");
  2. //use < Length-1 to ensure you ignore the last word
  3. for (int i=0; i<arr.Length-1;i++)
  4. {
  5.  string temp=arr[i];
  6.  //do whatever you want with temp
  7. }
  8.  
or in vb.net:

Expand|Select|Wrap|Line Numbers
  1. Dim arr As String() = x.Split("\".ToCharArray()) 
  2. 'use < Length-1 to ensure you ignore the last word 
  3. For i As Integer = 0 To (arr.Length - 1) - 1 
  4.     Dim temp As String = arr(i) 
  5.     'do whatever you want with temp 
  6. Next 
  7.  
Sir the codes that you give..only the last words is displayed like for example..
cafe\restaurant \hotel..in your codes the cafe\restaurant is deleted the hotel is displayed..how i'm going to fix that codes..i want to display only the words..cafe\res taurant but not the lastword which is \hotel..help me again to keep the first and second word not the last word..thanks again
Oct 5 '07 #4
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
Hi,
could you please put in what you are doing with the code sent above.

The code given by Plater is 100% to what you should need.
Its what you are doing with it matters.

cheers
Oct 5 '07 #5
Plater
7,872 Recognized Expert Expert
I will try again as a bit of pseudo code
Expand|Select|Wrap|Line Numbers
  1. string mys= "cafe\restaurant\hotel";
  2. //and then you Split() it
  3. string[] pieces = mys.Split(@"\".ToCharArray());
  4. //then pieces will now look like this:
  5. //pieces[0]="cafe";
  6. //pieces[1]="restaurant";
  7. //pieces[2]="hotel";
  8.  
  9. //Now you need to loop from index 0 to index 1 
  10. //since pieces.Length=3,  and you only want index's 0,1
  11. //you would use < pieces.Length-1 
  12. for (int i=0;i<pieces.Length-1,i++)
  13. {
  14.   string temp=pieces[i];
  15.   //now temp will = "cafe" when i=0 and "restaurant" when i=2
  16.   //if I have to explain more loop logic to you, you really need to go 
  17.   //back and read some tutorials on "the basics"
  18. }
  19.  
Oct 5 '07 #6

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

Similar topics

6
10885
by: Bimo Remus | last post by:
Hi, I am currently taking a C++ class and am having problems with a homework assignment. My problem is that I need to pull the first and last words out of of a character string array which is in the form title firstName lastName. The chapter that this assignment is on deals with string arrays and includes pointers. I've seen how one can reverse the order of letters in a word using pointers so thought maybe I could discern the last word...
20
5171
by: Tom Warren | last post by:
Is there a formal name for the (Mc,Mac,O,Van...) part of a last name? Tom
32
4158
by: James Curran | last post by:
I'd like to make the following proposal for a new feature for the C# language. I have no connection with the C# team at Microsoft. I'm posting it here to gather input to refine it, in an "open Source" manner, and in an attempt to build a ground-swell of support to convince the folks at Microsoft to add it. Proposal: "first:" "last:" sections in a "foreach" block The problem: The foreach statement allows iterating over all the...
11
6799
by: arnuld | last post by:
C takes input character by character. I did not find any Standard Library function that can take a word as input. So I want to write one of my own to be used with "Self Referential Structures" of section 6.5 of K&R2. K&R2 has their own version of <getwordwhich, I think, is quite different from what I need: <getwordwill have following properties: 1.) If the word contains any number like "beauty1" or "win2e" it will
209
8888
by: arnuld | last post by:
I searched the c.l.c archives provided by Google as Google Groups with "word input" as the key words and did not come up with anything good. C++ has std::string for taking a word as input from stdin. C takes input in 2 ways: 1) as a character, etchar() 2) as a whole line, fgets()
3
2791
by: houghi | last post by:
I have a parameter $name that contavins e.g. "Turn left at Blooming Grove Turnpike/Quassaic Turnpike/RT-94 Continue to follow RT-94". I just want to have the last word. The number of words will be different each time. I looked at http://be.php.net/manual/en/book.strings.php but I either did not see it or I am looking at the wrong place (or both) houghi --
2
1850
by: whodgson | last post by:
The following code accepts a string from the user and swaps the first and last letters in each word. It prints out the original string incorrectly by dropping off the first letter of the first word. I would like to establish what error in the code is causing the first word to be mangled. #include<iostream> #include<cstring> #include<cstdlib> using namespace std; int main() { cout<<"Transposing letters in a string \n"; cout<<"Type a...
2
4953
by: mburns | last post by:
Hello all- I was wondering if it is possible to link an Access query or table to a Word document and pull specific information into Word by manually entering a unique identifier, which would then pull all related fields from Access to the Word document. My goal is to develop a Word template that pulls certain fields from an Access query or table. For example, some of the fields I would like to pull from Access are etc..... But I would...
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9543
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10488
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10029
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7567
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6808
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5588
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4144
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.