Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

taking 7 digits from database

 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am storing a callerid number in a table.I need to get only the last 7 digits
from the callerid and i have to display it.for example if i am storing 043255667778.i have to get 5667778 and to display it.how can i do this?using substring?please help me to do this.

Thanks
 
amitabh mehra
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From what I understood from your description is that you are storing a caller id in some database table as a varchar. And later, after retrieving you want to display the last 7 digits using substring function.

If this is correct then you can try: (assuming you fetched the string in str variable of type string)

String lastSeven = str.substring(str.length() - 7);
 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks.it is working.
[ May 28, 2008: Message edited by: preethi Ayyappan ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alternatively, you could do this directly in SQL. Depending on the number of records you are retrieving, this might reduce the network bandwidth consumed by the database query.

http://www.1keydata.com/sql/sql-substring.html
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MS SQL (and perhaps others) also have methods called LEFT and RIGHT. Perhaps you can use those too:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic