Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,551 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,881 people online right now. Registration is fast and FREE... Join Now!




Split the text

 
Reply to this topicStart new topic

Split the text, Split the text

VAP001
12 Aug, 2008 - 10:23 PM
Post #1

New D.I.C Head
*

Joined: 12 Aug, 2008
Posts: 2

smile.gif [font=Verdana][size=7]

I have different type of text line which is different length. I want to split that text line and save paricular word from text line in variable. What is the solution for this??????
Eg of text line : Dubai,Cargo Release,(ML)(Maersk Line (Dubai))
from above textline I want "Dubai" word that is present in brackets.

Pls help........

User is offlineProfile CardPM
+Quote Post

jens
RE: Split The Text
13 Aug, 2008 - 01:37 AM
Post #2

D.I.C Head
Group Icon

Joined: 9 May, 2008
Posts: 113



Thanked: 3 times
Dream Kudos: 150
My Contributions
QUOTE

I want to split that text line and save paricular word from text line in variable. What is the solution for this??????
Eg of text line : Dubai,Cargo Release,(ML)(Maersk Line (Dubai))
from above textline I want "Dubai" word that is present in brackets.


In the code below temp is a string containing the line of text and find is the text you are looking for. The posFound variable holds the position of the start of find within temp. E.g: if temp = "here you go" and find = "yo" posFound will become 6.

You do know that Dubai is in brackets, you also know that Dubai will be found in a position which is larger then the position of the string ")(". You can make a temporary string of whatever is present after the ")(" and in the temporary string search for "(". Otherwise, maybe there's some string function that will find a certain substring that will accept a starting point to look at...

This is VB6 code:
CODE

# posFound = InStr(UCase(LTrim(temp)), UCase(find))  
# If posFound > 0 Then  
#   'If you land here you have found the string and you know  
#   'what position it starts in.  
#   'Look at e.g: <a linkindex="162" href="http://www.example-code.com/vb/string.asp" target="_blank">http://www.example-code.com/vb/string.asp</a>  
#   'and especially at "string length" and "extract substring"  


The UCase stuff makes whatever you feed it with become ALL CAPITALS which comes in handy if you don't know if the string you are searching through is CAPITALS or not.
The LTrim thingy makes spaces (blanks) in the beginning of the string go away.

Just a hint
/Jens

This post has been edited by jens: 13 Aug, 2008 - 01:38 AM
User is offlineProfile CardPM
+Quote Post

thava
RE: Split The Text
13 Aug, 2008 - 05:38 PM
Post #3

D.I.C Regular
Group Icon

Joined: 17 Apr, 2007
Posts: 450



Thanked: 18 times
Dream Kudos: 50
My Contributions
it is simple to find to given word but for a general solution
give some more examples and some more words to make an algorithm

it is simple to find to given word but for a general solution
give some more examples and some more words to make an algorithm
User is offlineProfile CardPM
+Quote Post

VAP001
RE: Split The Text
13 Aug, 2008 - 06:16 PM
Post #4

New D.I.C Head
*

Joined: 12 Aug, 2008
Posts: 2

QUOTE(thava @ 13 Aug, 2008 - 06:38 PM) *

it is simple to find to given word but for a general solution
give some more examples and some more words to make an algorithm

it is simple to find to given word but for a general solution
give some more examples and some more words to make an algorithm



Eg. Text Line :

1> KCM Cargo Release,MSL (POLCSIKCM)
2> Hamburg Import Order Handling (saf)(Safmarine Line(Hamburg))

User is offlineProfile CardPM
+Quote Post

jens
RE: Split The Text
14 Aug, 2008 - 03:21 AM
Post #5

D.I.C Head
Group Icon

Joined: 9 May, 2008
Posts: 113



Thanked: 3 times
Dream Kudos: 150
My Contributions
QUOTE

1> KCM Cargo Release,MSL (POLCSIKCM)
2> Hamburg Import Order Handling (saf)(Safmarine Line(Hamburg))


0) copy the string to a temporary string.
1) check the length of the string. (string functions again)
2) while the last character of the string is ")" delete last character.
3) Looking from the end of the string find index of character "("
4) Now use another string function to get a substring out of your temp string. Pick all characters from index from (3) above to the end.
Done. smile.gif

/Jens
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 11:11PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month