Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I have a property table that has addresses like below.

12 Andrews CL, Pxxx
1/12 Andrews CL, Pxxx
2/31 Macrossan ST, Pxxx
2/7-11 Barrier   ST, Pxxx

I need to only show

12
1/12
2/31
2/7-11

Can this be done within the expression builder in Mapinfo 12?

In python it would be something like address[:address.find(' ')]

share|improve this question
up vote 3 down vote accepted

Yes, you can do this by using the Left$ and InStr functions as below. Check out the MapBasic Reference Guide (should be available in the Documentation folder of your MapInfo installation) for detailed information about those functions, along with a whole host of others.

Left$(address,InStr(1, address, " ") - 1)
share|improve this answer
    
You beat me to it by a few seconds, @T_Bacon :-) – Peter Horsbøll Møller Feb 24 at 13:55
    
So whose answer should I pick? you both answered the same but neither of them get all characters from the left up to the first space. Thanks for pointing me to the reference guide. I didn't know it was there. – GeorgeC Feb 24 at 14:42
2  
Pick this one as he posted the answer seconds before me ;-) – Peter Horsbøll Møller Feb 24 at 14:55
2  
Thanks Peter, you can have the next one! ;-) – T_Bacon Feb 24 at 14:57
1  
@GeorgeC - Or you could do it through MapBasic as Peter has suggested in the comments for his answer. – T_Bacon Feb 24 at 16:07

Try this:

Left$(ADDRESS, (InStr(1, ADDRESS, " ") - 1))

This will show the string to the left of the first space characters. ADDRESS is here the name of the column

share|improve this answer
    
Thanks. It is printing Pxxx rather than 1/12. I want it to print from the first character upto the first space character. – GeorgeC Feb 24 at 14:38
    
Are you saying it's printing the characters from the right instead of the characters from the left? – Peter Horsbøll Møller Feb 24 at 14:56
    
Is the perceived space in fact a tab character by any chance? Try changing this bit: InStr(1, ADDRESS, " ") to InStr(1, ADDRESS, Chr$(9)), that might fix it. – T_Bacon Feb 24 at 14:57
    
So if the full address is "1/12 Davidson ST, PORT SMITH" it is printing "Port" but it should print 1/12. How do I tell if it is a tab? it's all in one address field as {1/12 Davidson ST, PORT SMITH} – GeorgeC Feb 24 at 15:00
1  
Try this to figure out what character it is: select the object in the map and run these two statements via the MapBasic window which will print the ascii# of the character to the message window. The number 5 refers to the character you want to inspect: Fetch First From Selection Print Asc(Mid$(ADDRESS, 5, 1)) – Peter Horsbøll Møller Feb 24 at 15:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.